Long time no blog !.
Last year I working on new type of connection probe for one of the private Torrent tracker in Thailand. So ~150000 Peers and around ~15000 clients out there. (Prove that bittorrent users typically run average of 10 torrents). It previously work using 1 process to start serveral child process for processing and die.
I just upgraded it to work as Daemon with new interprocess communication things. It work by simple unix based named socket. It work the same way that preforked daemon usally do with one master process to distribute request to clients.
But ... you may surprise -- It wrote with PHP not C, Java, Perl, Python. Dynamic languages is seems to work well for this too if it supports. This almost the C wrapper so memory leak is no probably exists. (but PHP parser itself usually have memory leaks).
Meanwhile PHP usually not good in memory conservation. My server got some errors on PHP script that decode (bencoded) .torrent files and ... Hey ... 128 MB memory was exhaust. Why, .torrent is just around 300k in size.
I figured out that PHP structure usually allocate memory in chunk. And PHP store variables that use small memory together. But sometimes it fragments so much and PHP does not good on handle memory fragment.
I use memory_get_usage(true) to check how much memory was allocated. That 300k .torrent files use as much as 136MB of memory after parsed (that memory_get_usage(true) report). But memory_get_usage(false) will give real memory usage of PHP (not alloated memory). It gives only 28MB.
So PHP not good when handle memory fragments.



0 Trackbacks