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) »
  • localisation makes civicrm slow
Pages: [1] 2

Author Topic: localisation makes civicrm slow  (Read 2604 times)

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
localisation makes civicrm slow
November 13, 2011, 12:58:34 pm
Hello there,

I had been experiencing slowness on a few different sites recently.  On two seemingly very similar sites on the same host, I was seeing one site out perform the other by a significant amount, and this was especially noticable / critical when it came to Ajax calls.

After looking at a simple javascript call with xdebug at the Albany code sprint, we worked out that loading the localisation files was putting a big strain on the server.

On a simple ajax call (which actually was returning an error message) FileReader->read had an 'invocation count' of 16813 and a 'total self cost' of 35%.

A proposed solution was to look into apc and making sure that the translation file (e.g. civicrm/l10n/en_GB/civicrm.mo is 901K) got cached with apc.

But this doesn't seem to work.  Seems like my apc is (probably reasonably) not caching .mo files.

I am wondering how I can get this file cached?

Or maybe there is a different approach / something else I am missing

I did see this post about caching the translation object in wordpress land and wondered if a similar approach could be taken with civicrm.  http://wordpress.org/extend/plugins/cache-translation-object/

My short term solution was to turn off translation.  That is an option for me because en_GB is not too different from en_US, but that is obviously not normally an option for other languages.

Thoughts very much appreciated.

Michael
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: localisation makes civicrm slow
November 13, 2011, 02:28:25 pm
Yep, I found that localisation has a big speed impact (20% of page load )- I did write on this a while back

http://forum.civicrm.org/index.php/topic,20697.msg86495.html#msg86495

I did try turning translate off (these are US sites anyway) but have recently turned it back on as the method I used to do that seemed to be causing a minor problem.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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: localisation makes civicrm slow
November 13, 2011, 06:52:22 pm

might want to ping bgm on IRC since he seems to know a fair amount about localization and APC

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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: localisation makes civicrm slow
November 13, 2011, 10:22:30 pm
Do we need localisation on the API calls?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: localisation makes civicrm slow
November 14, 2011, 01:39:04 am
Hey Xavier,

The particular problem for me was in Ajax autocomplete since this could often be called 15 to 20 times in a few seconds by a single operator (try and find 'McAndrew, Michael' or 'Third Sector Design' :)  Multiply that by a few people in an office trying to look for someone and my server began to not like it.

It seems like most autocompletes and a lot of ajax, if they are just returning DB data with name values wouldn't need any localisation.

I'll ping bgm and we can see what he says...

Michael


Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: localisation makes civicrm slow
November 16, 2011, 06:14:56 am
Quote
Do we need localisation on the API calls?

The major pain is when the request gets generatered ~30 times in the space of a few seconds.  I guess you can't tell how someone is using the API and it would be good to turn it off anywhere when it is not necessary.  In other instances, it isn't an unbearable overhead, I guess.
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: localisation makes civicrm slow
November 16, 2011, 07:37:10 am
Hi,

I know that hartmut did investigate and found some tricks for big improvements. Can you ask him on IRC next time you see him?

Quote from: michaelmcandrew on November 16, 2011, 06:14:56 am
Quote
Do we need localisation on the API calls?

The major pain is when the request gets generatered ~30 times in the space of a few seconds.  I guess you can't tell how someone is using the API and it would be good to turn it off anywhere when it is not necessary.  In other instances, it isn't an unbearable overhead, I guess.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: localisation makes civicrm slow
November 16, 2011, 08:02:43 am
Looking forward to what you discover - I'm preparing a tri-lingual install that is about to go to QA testing...
Lead Developer, C3 Design.
Twitter: @FatherShawn

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: localisation makes civicrm slow
November 16, 2011, 11:59:42 am
Unfortunately I don't have much to add except that with the PHP "APC"  cache I do not have this performance issue (most of my sites are in French).

However, in Albany I checked on Michael's dev environment, and for some reason, APC was not helping at all. But in theory, and in my dev/prod environments, I measured with xdebug a clear improvement when APC is active. ACP keeps the ~ 1 mb file in memory and avoids loading it every time.

You also need to make sure your operating system has enough RAM to be able to cache the files. For Apache/MySQL, I never work with less than 1 GB of ram.

Xavier was asking if it's necessary to load the translation in API calls: the way the code works, it loads the translation file when ts() is first called. But it might be worth tracing why ts() was called for an auto-complete on a contact name.

In terms of bigger changes, I often wonder if a DB-based solution such as Drupal's is better (for example, translating CiviCRM extentions is not easy right now). Drupal loads only the necessary translations on each request, but it does a "select" query for each string. On the other hand, most of those queries get cached in MySQL. I rarely have seen people complain about Drupal's i18n performance because of those queries.
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: localisation makes civicrm slow
November 16, 2011, 01:43:32 pm
Hi,

For what I remember, a lot of things are loaded (or memory used, or CPU, or something). Not sure if there is a ts() somewhere in the code around the api (I don't think so).

I just did a completely informal test on a french install on my laptop: ran using the API explorer on a small (test) db on a contact.get, email.get, constant.get...

I get between 500ms and 1000ms by randomly switching between api calls. When I run the same api (presumably when everything in in the memory), it doesn't go under 250ms.

To everyone: Could you try this test on your configuration?

I personally find it super slow.  I'd have as a goal to have it max at 300ms. That's way enough CPU cycles to do a few SQL queries and converting to json and push that on the computer.

Might be worthwhile adding a timer when debug=1 and returning it as part of the result?

Another thing that I find "big" is the config object that contains the list of enabled countries. I my case, they are always all enabled. An array of a few hundred strings is not that big, but wondering if they aren't multiplied (eg is the one assigned in smarty a copy or the same as the one returned by the factory in PHP?

X+
« Last Edit: November 16, 2011, 01:52:02 pm by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: localisation makes civicrm slow
November 16, 2011, 11:45:51 pm
Hitting the ajax contact_get url causes crm_translate to be called 398 times.

Most of them seem to be as part of getfields which in turn calls $BAO::fields which turns out to be a fairly slow function as it calls 'ts' many times
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: localisation makes civicrm slow
November 17, 2011, 02:18:12 am
Are you on debug mode? (getFields is definitely used for that)

Is there a way to switch language for a while (eg. I don't think it's a good idea to translate fields in the API) ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: localisation makes civicrm slow
November 17, 2011, 11:03:27 am
It's not about language - the function still hits performance when your language is set to US English.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

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: localisation makes civicrm slow
November 17, 2011, 01:08:04 pm

other than the overhead of so many calls to ts, why do u think there is a performance penalty for US english?

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: localisation makes civicrm slow
November 17, 2011, 02:01:58 pm
I haven't done much more than a quick look this time but I remember last time I tried changing to a custom translate function (replace crm_translate with something that did nothing) & got a boost on performance.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • localisation makes civicrm slow

This forum was archived on 2017-11-26.