[drupal-devel] Memory profiling for modules
Hi folks, I was installing Civicspace a little while ago and was surprised that the installer recommended a non-standard memory_limit (8Mb is likely what most hosts provide and expect it is what most distros send php out with). I decided to set it up with 8M locally anyways, and most stuff seems to run except for a list of admin modules: ?q=en/admin/modules Neil Drumm informed me that the modules page "needs to get the metadata for all the modules which is stored in each module's php code. So that page loads /every/ module. That takes a lot of memory." Might be good to build some type of pagination in here for users who don't have a lot of flexibility with their web hosts, root access or confidence to muck about in the php.ini file. Anyways, I created this small patch to the drupal CVS which would allow developers to pretty quickly see what modules are sucking up the most memory: It produces results like this (although this is based on CivicSpace 0.8.1.2 code): Memory Usage before modules are loaded: 1,148 Kb Memory Usage (1) block: 1,267 Kb -- Change 119 Kb + Memory Usage (2) blog: 1,327 Kb -- Change 60 Kb Memory Usage (3) book: 1,499 Kb -- Change 173 Kb + Memory Usage (4) comment: 1,903 Kb -- Change 404 Kb ++++ Memory Usage (5) contact_manager: 2,255 Kb -- Change 352 Kb +++ Memory Usage (6) contact_manager_forms: 2,319 Kb -- Change 64 Kb Memory Usage (7) drupal: 2,371 Kb -- Change 52 Kb Memory Usage (8) filter: 2,592 Kb -- Change 222 Kb ++ Memory Usage (9) forms: 2,659 Kb -- Change 66 Kb Memory Usage (10) forum: 2,873 Kb -- Change 214 Kb ++ Memory Usage (11) help: 2,889 Kb -- Change 16 Kb Memory Usage (12) massmailer: 3,211 Kb -- Change 322 Kb +++ Memory Usage (13) menu: 3,325 Kb -- Change 114 Kb + Memory Usage (14) node: 3,719 Kb -- Change 394 Kb +++ Memory Usage (15) node_import: 3,799 Kb -- Change 80 Kb Memory Usage (16) notify: 3,816 Kb -- Change 17 Kb Memory Usage (17) page: 3,829 Kb -- Change 12 Kb Memory Usage (18) path: 3,885 Kb -- Change 56 Kb Memory Usage (19) phplist: 3,996 Kb -- Change 111 Kb + Memory Usage (20) search: 4,132 Kb -- Change 137 Kb + Memory Usage (21) statistics: 4,241 Kb -- Change 109 Kb + Memory Usage (22) story: 4,253 Kb -- Change 11 Kb Memory Usage (23) system: 4,445 Kb -- Change 192 Kb + Memory Usage (24) taxonomy: 4,683 Kb -- Change 238 Kb ++ Memory Usage (25) textile: 5,308 Kb -- Change 625 Kb ++++++ Memory Usage (26) urlfilter: 5,316 Kb -- Change 9 Kb Memory Usage (27) user: 5,802 Kb -- Change 486 Kb ++++ Memory Usage (28) watchdog: 5,840 Kb -- Change 38 Kb Memory Usage after all modules are loaded: 5,840 Kb I think that this could be useful for other folks who are looking at general profiling issues too. You need to enable the code by turning $profileMemory = true; There's likely a more graceful way to do this, but I'm still rather new to Drupal. This code also only works if you have memory_get_usage in your php install. Mike -- Mike Gifford, OpenConcept Consulting Free Software for Social Change -> http://www.openconcept.ca Latest launch Canadian Labour Congress / Congrès du travail du Canada http://canadianlabour.ca / http://congresdutravail.ca
On Wed, 10 Aug 2005, Karoly Negyesi wrote:
the most memory:
Memory Usage (28) watchdog: 5,840 Kb -- Change 38 Kb Memory Usage after all modules are loaded: 5,840 Kb
Note that the memory usage looks as if it would grow in parallel to the number of lines a module has.
And this is what I never understood. If after 28 modules only 5840 kbytes are consumed why Drupal needs 8, 16 sometimes even more megabytes?
If you want to investigate it I suggest that you wrap Mike's code into a function, put calls to it in strategically chosen places, and look what happens. :) I suspect that the menu will make up for a fair portion of the used memory. Cheers, Gerhard
the most memory:
Memory Usage (28) watchdog: 5,840 Kb -- Change 38 Kb Memory Usage after all modules are loaded: 5,840 Kb
And this is what I never understood. If after 28 modules only 5840 kbytes are consumed why Drupal needs 8, 16 sometimes even more megabytes?
I don't see what is confusing. This memory consumption is only what takes up to include all the files, doing no serious stuff (ie. big data loading, image processing, etc). BTW you can easily go above 50 modules (not all enabled :) on a complex site. Goba
On Aug 10, 2005, at 11:08 AM, Gabor Hojtsy wrote:
the most memory:
Memory Usage (28) watchdog: 5,840 Kb -- Change 38 Kb Memory Usage after all modules are loaded: 5,840 Kb
And this is what I never understood. If after 28 modules only 5840 kbytes are consumed why Drupal needs 8, 16 sometimes even more megabytes?
I don't see what is confusing. This memory consumption is only what takes up to include all the files, doing no serious stuff (ie. big data loading, image processing, etc). BTW you can easily go above 50 modules (not all enabled :) on a complex site.
CivicSpace ships with 61 and is about to ship with a lot more. Mike, could you turn off all the blocks, in particular the menu navigation block and see if that changes things. Thanks, Kieran
Goba
participants (5)
-
Gabor Hojtsy -
Gerhard Killesreiter -
Karoly Negyesi -
Kieran Lal -
Mike Gifford