PHP Memory limit

Posts: 3
Joined: 03/12/2008

So I was getting some WSOD on an ubercart site in development.

error_log wrote:

PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 523331 bytes) in …

The hosting site limits the PHP memory to 32M, no matter what you put in the .htaccess file, so I can't increase the memory limit.

I've enabled devel module's “Display memory usage” functionality (on the dev site with a copy of the live db, not the live site with the memory limit) and I'm seeing:

devel wrote:

Memory used at devel_init(): 36.43 MB
Memory used at devel_shutdown(): 37.11 MB

This is a complex site with lots of modules…

module_list() wrote:

block
contact
content (cck)
date (cck)
date_api (cck)
devel
extlink
fieldgroup (cck)
filter
googleanalytics
help
htmlbox
imagefield (cck)
inline
jquery_update
ksite (custom)
menu
menu_block
node
nodequeue
nodereference (cck)
number (cck)
optionwidgets (cck)
path
path_redirect
search
securepages
system
tapir
teachers (custom)
test_gateway
text (cck)
token
ubrowser
uc_attribute
uc_cart
uc_cart_links
uc_credit
uc_donate
uc_donation
uc_googleanalytics
uc_notify
uc_order
uc_payment
uc_product
uc_reports
uc_stock
uc_store
upload
user
views
views_rss
views_theme_wizard
views_ui
watchdog
workflow_ng
workflow_ng_ui
xmlsitemap
xmlsitemap_node

I've already disabled modules to try to get this as lean as possible.

When I disable UC and its dependencies, the memory usage drops dramatically.

devel wrote:

Memory used at devel_init(): 21.69 MB
Memory used at devel_shutdown(): 22.41 MB

That's nearly 15MB for Ubercart by itself (and I'm only using a select list of UC modules.)

Any suggestions on how I can get a UC site's PHP memory usage under 32M?

Posts: 104
Joined: 01/11/2008

Depending on your web host you might have to set the php memory in a php.ini file and not .htaccess.

Posts: 348
Joined: 10/16/2007

And check out drupal.org as there is a lot of information on this topic as this is primarily a Drupal issue.

Posts: 904
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

Here are some measurements: http://www.ubercart.org/comment/12308/Re-devel-module-has-setting
There are other methods for increasing PHP memory that don't involve .htaccess, shown at http://www.ubercart.org/faq/3072

Ubercart is big, for sure - bigger than Drupal itself - but that's because of all the features.Your problem is at least as much due to all those other modules you have installed as it is with Ubercart. 21+ MB without Ubercart is very large! If you really need to use all those modules, and the alternatives in the FAQ above don't work for you, then it's time to look at better hosting solutions.

Let me get on a soapbox for a minute... If you're setting up a site that sells things, you can afford to spend more than the $3.95 a month a shared hosting site costs. Just do the math - if your site goes down for one day, how much business will you lose? More than a VPS costs per *month*, easily. If you expect to make any sort of income from your web site, it just doesn't pay to deal with bargain-basement hosting companies. Find a package where you have complete control over things like PHP version, memory size, compiled-in options, MySQL version, etc. etc., and pay for the privileges and reliability that brings.

--

<tr>.

Posts: 4771
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Man, your post makes me feel like Ubercart is the fat guy in the pool squeezing all the little kids out. Sticking out tongue I don't have anything helpful to add to the thread atm, but hopefully we can work on these memory troubles w/ D6 and the new menu system. I'm not a great memory optimizer, but if you know of any things routinely used in PHP that eat up resources, I can let you know where we might be biting you and how we can improve.

This won't help for now, but at least when the site goes live you can disable the devel module and hopefully free up some resources. Puzzled Same for the Views Theme Wizard. Also, does your memory comparison include disabling Workflow-ng?

Posts: 1
Joined: 06/09/2008

The usual suspects for memory eating, IME, are code weight and large cached data structures. The $menu structure in D5 is decidedly not small, for instance.

For code weight, even in D5 you can do some nimble footwork to split off page handlers. See the way locale module handles it for a working if a bit ugly mechanism.

For large data structures, that's frequently cached data. While the look up in a giant array is far faster than hitting the database, hitting the database has less of a memory overhead if you're only pulling a few records. I have no idea what the code looks like now in UC, but that would be a place to look to change the trade-off.

Posts: 89
Joined: 11/06/2007
Bug FinderGetting busy with the Ubercode.

On every page load drupal_load() is run which loads all enabled modules files which get stored in the php memory. With Drupal 6 ability to attach files to specific paths allows for limited loading of code dependent on the path, very cool.

Solutions for Drupal 5 other than increasing the memory limit is to install APC or something like it, this could very well not be a possible solution for those in virtual servers hosting. Once APC (or something like it) is installed, you will see your memory usage drop dramatically. If you are use to seeing 30M - 40M, you would very likely be seeing 2M - 5M as a result of APC.

Posts: 4771
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Crell@drupal.org wrote:
The usual suspects for memory eating, IME, are code weight and large cached data structures. The $menu structure in D5 is decidedly not small, for instance.

Thanks so much for stopping by, Crell! I hadn't considered the $menu structure earlier today, and that is actually a large part of what makes up UC. Sad

I'll look into locale, but my bet is we're just going to have to wait till the D6 update is complete. In the meantime, I may try to make sure someone is tracking our memory usage while we port so we can try to lower our footprint...

@greenSkin - sounds interesting... do you have any stats for a live UC site by any chance?

Posts: 89
Joined: 11/06/2007
Bug FinderGetting busy with the Ubercode.

Yes, I can get some stats tomorrow from a live Ubercart site. What sort of information would you like to know, just the memory usage with and without APC?

Posts: 4771
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

greenSkin wrote:
Yes, I can get some stats tomorrow from a live Ubercart site. What sort of information would you like to know, just the memory usage with and without APC?

That'd be great. Smiling

Posts: 89
Joined: 11/06/2007
Bug FinderGetting busy with the Ubercode.

Here's the with APC and without APC memory usages for the front page of www.itiswritten.com. The 'Picture 1' is with APC and 'Picture 2' is without.

AttachmentSize
Picture 2.png11.74 KB
Picture 1.png11.89 KB
Posts: 904
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

Wow. Are there other noticeable impacts on performance other than memory reduction? What do your page load times look like?

--

<tr>.

Posts: 89
Joined: 11/06/2007
Bug FinderGetting busy with the Ubercode.

Page load times are substantially faster and again these results were taken from the front page of www.itiswritten.com.

'Picture 1' is with APC and 'Picture 2' is without.

AttachmentSize
Picture 2.png6.68 KB
Picture 1.png6.54 KB