Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A Daemon on the Rocks

I am writing a daemon in PHP. I did not take a OS class in college. So, I'm wondering, what are the server/other statistics that I need to be looking at to make sure my Daemon is not consuming too much system resources and will be able to scale when there are more mysql records. Basically, my daemon is processing a bunch of mysql table rows.

For example, I understand I need to see how long the daemon is taking to process a certain number of rows, and the amount of memory it is using. But, how do I determine if it is leaking memory? Also, what other system parameters should I be judging the daemon by?

like image 990
Chris Hansen Avatar asked Nov 04 '22 02:11

Chris Hansen


1 Answers

But, how do I determine if it is leaking memory?

The stuff you're asking about here has little to do with the operating system. You're right to be concerned about memory usage. A proper answer to this question goes way beyond the scope of a post here but you might want to start by looking at how reference counting works for memory management, and make sure you've got the circular reference checker configured in your PHP installation. The plot thickens when you discover that the mysql client blocks PHP while it is running and ignores PHP's memory limits - so if you fetch too large a result set, you won't know about it until mysql_query returns and your code falls over: always use LIMIT in queries (or PK selection) and for preference run the daemon under a watchdog. Test using varying memory limits lower than you intend to use in production.

Note that PHP will only start making more memory available to itself via garbage collection when it thinks it's running out of memory.

Write lots of stuff to log files!

like image 186
symcbean Avatar answered Nov 07 '22 21:11

symcbean