developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 10 years ago

Closed 10 years ago

#1237 closed enhancement (fixed)

Add locks to jCache::call to prevent multiple calls on CPU high-consuming functions

Reported by: bricet Owned by:
Priority: normal Milestone: Jelix 1.2RC3
Component: jelix:utils Version: trunk
Severity: normal Keywords: jcache call lock performance
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description

When calling jCache::call, we me be faced to a problem when calling a function which needs a lot of CPU time to run.

Indeed, on heavy traffic site, several client requests may all lead to a jCache:call on a single function with the same args. As the results of this function call is cached after this function answered, we may have a call for each request if this function lasts too long.

I propose to have a lock system to prevent this. The way it works in my patch is to insert a lock as a jCache value before function call and delete it after function results has been stored. Other clients wait for the lock to be released and then read the JCache value stored by the first call (of the first request) to jCache::call.

This patch has not been production-tested yet. But it works on my dev machine.

I managed to prevent the lock from being eternal to avoid side-effects (e.g. killing web server while the function called by jCache::call is running). May be we should also try{ } catch{ } this function call. I let PHP gurus having a better point of view about this ...

Attachments (2)

ticket_1237.diff (1.5 KB) - added by bricet 10 years ago.
ticket_1237_2.diff (1.8 KB) - added by bricet 10 years ago.

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by bricet

comment:1 Changed 10 years ago by bricet

After thinking again about it, here is a new patch which should lead to fewer accesses to jCache readings.

Changed 10 years ago by bricet

comment:2 Changed 10 years ago by laurentj

  • Milestone set to Jelix 1.2

comment:3 Changed 10 years ago by laurentj

  • Resolution set to fixed
  • review changed from review? to review+
  • Status changed from new to closed

Seems to be ok for me.I justed changed the name of the lock key, to minimize the conflict with a "real" key.

https://bitbucket.org/jelix/jelix-trunk/changeset/217310858586

Note: See TracTickets for help on using tickets.