Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Logging and performance

by weismat (Friar)
on Feb 18, 2008 at 10:10 UTC ( [id://668499]=perlquestion: print w/replies, xml ) Need Help??

weismat has asked for the wisdom of the Perl Monks concerning the following question:

I am currently adjusting a program which reads lots of data via 2 sockets to write a log file with all read data.
The data volume is between 1 and 2 KByte per second on one socket and significantly less on the other socketbr> The reason for the logging of all messages from both sockets is to synchronize the received data.
I am currently using Log-Dispatch-Rotate for the logging and I am a bit concerned that this program seems to flush after every line. Which other module would you recommend for logging? It should also work from multiple threads when the logging gets initialised before the child threads start.
Any help would be highly appreciated.

Replies are listed 'Best First'.
Re: Logging and performance
by loris (Hermit) on Feb 18, 2008 at 10:48 UTC

    I am not sure that it would help you with your specific issues (although I don't think that threading would be a problem), but Log::Log4perl is perhaps worth looking at.

    loris


    "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ." (from "Slow Loris" by Alexis Deacon)
Re: Logging and performance
by pc88mxer (Vicar) on Feb 18, 2008 at 15:30 UTC
    First of all, I'd say that 2K per second is _not_ a lot of data. If your program is not keeping up with the input streams, post your code, and I'm sure we can figure out what's holding it up.

    Also, I think that most logging systems will flush at the end of each line since the purpose of a logging module is to save the log message to permanent storage especially in the event that the program crashes shortly afterwards. Still, flushing should not significantly slow your program down. Again, if it is, show us what your code is like, and we can suggest how to improve it.

Re: Logging and performance
by kyle (Abbot) on Feb 18, 2008 at 16:21 UTC

    Are you sure that logging is the problem? You should profile your code to find out where it's really is spending its time before you worry about optimizing some part of it. It's possible that logging is not a big enough part of your execution time to be worth optimizing.

Re: Logging and performance
by tilly (Archbishop) on Feb 19, 2008 at 07:55 UTC
    You seem have contradictory requirements. You want it to work with multiple threads. But you also want buffered output. But buffered output means that one thread will write out a block, ending with part of a line, then other threads will write out data before the first thread finishes its line. That will result in corrupted output.

    As others have said, try it and see what performance looks like. My bet is that performance will be just fine. After all flushing after a print just means that a block of data is sent to the filesystem. It does not mean that a write happens immediately to disk. Sure, one will happen when the filesystem gets around to it. But pages are generally left dirty in memory for a bit. And as I noted above, the flushes are necessary anyways if you want to be able to avoid having multiple threads cause you headaches.

      Unfortunately the performance is not fine. I gave also a wrong number for the data per second - in fact we are talking about up to 100 KByte per second with a base load of maybe 20 KByte/second.
      I guess I will need to move the logging into a seperate thread - so that the application will keep its speed.
        I moved the logging into a seperate thread.
        It was way too slow using the logfile write - I had only about 600.000 lines of constant back log.
        Now I have moved to a standard file and the performance is ok.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://668499]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found