ExifTool Forum

ExifTool => Developers => Topic started by: nagibator on September 13, 2018, 11:30:44 AM

Title: usleep(1000)
Post by: nagibator on September 13, 2018, 11:30:44 AM
Hi guys. Currently I'm working on metadata writing app based on Exiftool.  I have some problems with performance and after some debugging I've spotted that this code takes a lot of time:
for (;;) {
        cmdNum = mStdout.Read();
        if (cmdNum) break;
        if (getTime() >= doneTime) break;
        if (mCmdQueue) Command();   // keep sending queued commands
        usleep(1000);               // chill and have a beer
    }


Why here execution is blocked for 1000 micro seconds? I've deleted this line and I won ~3 seconds, but I think this line is important, isn't it?
Title: Re: usleep(1000)
Post by: Hayo Baan on September 15, 2018, 04:31:08 AM
Where did you find this piece of code? It's not part of exiftool (which Is 100% Perl, not C).
Title: Re: usleep(1000)
Post by: StarGeek on September 15, 2018, 11:30:25 AM
Looks like it's part of the C++ Interface (http://owl.phy.queensu.ca/~phil/cpp_exiftool/) in the ExifTool.cpp file.
Title: Re: usleep(1000)
Post by: nagibator on September 17, 2018, 04:55:09 AM
Quote from: Hayo Baan on September 15, 2018, 04:31:08 AM
Where did you find this piece of code? It's not part of exiftool (which Is 100% Perl, not C).
This part of C++ Exiftool interface
usleep(1000) //line 718
usleep(100) //line 229
Title: Re: usleep(1000)
Post by: Hayo Baan on September 17, 2018, 06:56:04 AM
It was about time I had a look at the C++ interface, so thank you for your question :)

The sleep of one millisecond is (most likely) there only to prevent burdening the processor continuously with the loop execution. I'm surprised you actually notice this delay (unless you are using a very long list of commands), but it should be safe to make the delay smaller or even zero (though in the latter case one processor core will be used at 100% capacity during the loop run). The change should be made at line 718.

Cheers,
Hayo
Title: Re: usleep(1000)
Post by: Phil Harvey on September 17, 2018, 07:52:49 AM
Yes.  That delay is there just to prevent the process from using 100% of the CPU when it is doing nothing.

- Phil
Title: Re: usleep(1000)
Post by: nagibator on September 24, 2018, 05:19:53 AM
Thanks guys!