CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • limit civicrm include to save memory, make sense?
Pages: [1]

Author Topic: limit civicrm include to save memory, make sense?  (Read 688 times)

jimyhuang

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 3
limit civicrm include to save memory, make sense?
August 13, 2010, 07:40:48 pm
Recently, we met the same problem of civicrm + drupal exhaust much more memory. Every page need to allocate more than 40MB memory before deliver to client even if we use APC  or eaccelarator (before using, we need 100MB of memory).

So I go deep to watch some fat module / plug-in of drupal. Civicrm will make difference of 15-20MB to load after enable or disable civicrm.module.
Then I start to think why we need to initialize civicrm in every page? We don't want to boot ubercart in every page, because we don't need a shopping cart in whole site. Same with CRM, by the code of civicrm.module, I think only when we have block of civicrm / user page need to load civicrm. if we don't loading civicrm in every page, this will increase much performance in common drupal page, and when we need civicrm, it still there.

I start to trying this way, add a very little and dirty code to allow initialize civicrm only when such path:
Code: [Select]
function civicrm_initialize( ){
....
// when we would like to initialize ?
$allow_path = array(
  'user',
  'civicrm',
);
if(!in_array(arg(0),$allow_path)){
  return false;
}

// this does pretty much all of the civicrm initialization
$error = include_once( 'CRM/Core/Config.php' );

My question is:
Is something like this make sense for change civicrm.module to only allow some criteria then initialize civicrm?
Any potential risk or error on implement in this way?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: limit civicrm include to save memory, make sense?
August 13, 2010, 07:59:17 pm

1. we've gone to great efforts to make sure civicrm does not load on every page. However i think something crept into the hook_help function (not sure why that gets called on every page) which basically loaded civicrm

2. i dont think your patch will work, since some folks will call the api and use civicrm even when the url does not include user/admin/civicrm

3. can u try the below patch and see if that helps

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jimyhuang

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 3
Re: limit civicrm include to save memory, make sense?
August 18, 2010, 02:19:20 am
hi Lobo,

Thanks for providing the patch. Confirm the your patch work for our case. Before apply the patch, memory usage need 33MB on every page. After that, only need 15-20MB on page load.

I'll apply this patch to an online site, to see if any problem there. As I know of Drupal, seems it make sense to remove these civicrm_initialize on hook_help.

jimyhuang

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 3
Re: limit civicrm include to save memory, make sense?
August 18, 2010, 02:32:55 am
Here is the refine of your patch.  ;)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • limit civicrm include to save memory, make sense?

This forum was archived on 2017-11-26.