Post
Topic
Board Mining software (miners)
Re: Bitcoin Miners In Tray - a lightweight alternative to GuiMiner
by
WebMaka
on 28/04/2013, 22:53:00 UTC
Since I'm about to release a total-newbie-friendly GUI for Litecoin mining, lemme weigh in on something here that'll help you make your front-end a bit better...

Special note about Pooler’s cpuminer for Litecoins (https://bitcointalk.org/index.php?topic=55038.0) – Bitcoin Miners in Tray can run and control it, but due to two quirks, no output from cpuminer is displayed until it is stopped. Cpuminer directs all of its output to stderr, which BMT handles well. However, it does not finish output of a line when a line is written to stderr, thus all lines are dumped on the pipe at the same time when cpuminer stops and closes its streams. There is nothing I can do about it, as this needs to be fixed by Pooler.

I don't know what coding language you're using, but the way to work around this is to peek at the pipe with the PeekNamedPipe API call to see if there's anything in the pipe before trying to read it. Otherwise, your pipe read will deadlock trying to read an empty pipe. (For some reason, pipe reads on Windows like to hang when the pipe's empty, and trying to read an empty pipe will cause a wait state until the pipe has data to read.) Peeking at the pipe will allow testing it without reading from it, and that stops the wait state issue and allows you to continuously monitor the miner's output without having to wait for it to close.

I spent a lot of time trying to solve the "no data until the app closes" problem. I mean a lot of time. PeekNamedPipe turned out to be the solution.

Assuming you're peeking at the pipe, the only other issue you'll have is the fact that cpuminer - and, by extension, all of its forks - will not emit data across a pipe until it fills a send buffer that looks to be about 64KB. So, you'll end up with no reports at all for 5-15 minutes followed by a burst of text followed by more silence, rinse and repeat. This part will require resolution by the app coders themselves.

Here's how I'm handling this in my app - this code is Delphi 7 but should convert readily to whatever language...

Code:
            // This is an important bit of code: we take a peek at the output pipe
            // to see if there's any data in it. This allows us to avoid trying to
            // read from an empty pipe, which will just sit there and wait until
            // data comes in! This is the key to monitoring a console application
            // without having to wait for it to terminate before working with its
            // output.
            PeekNamedPipe(StdOutPipeRead, nil, 0, nil, @DataAvailable, nil);
            if (DataAvailable > 0) then
            begin
              // Since there's actually something to read, read it. Note that
              // we are reading blocks of 16 kilobytes of characters at a time.
              if ReadFile(StdOutPipeRead, Buffer, 16384, BytesRead, nil) then
              begin
                if (BytesRead > 0) then
                begin
                  // Make sure the boffer ends in a null character.
                  Buffer[BytesRead] := #0;

                  // Concatenate with any previous data.
                  Text := Text + Buffer;
                end;
              end;
            end;


Quote
CGMiner (https://bitcointalk.org/index.php?topic=28402.0) must be started with --text-only or -T parameter to disable ncurses and with --log 1 or -l 1 to log output every second. CGMiner suffers from the same problem as pooler’s cpuminer, which is not strange as it was forked from it. The problem is however only with the redirected stdout stream, while stderr works fine, outputting the lines as they are pushed into the pipe. Once CGMiner is stopped, all text on stdout will be dumped in one go. -l 1 seems to fix this.

I haven't had to add "-l 1" but "-T" was definitely a necessity.