•  » Engine
  •  » speed improvement, session automatic purge

#1 2014-05-02 11:01:42

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13878

speed improvement, session automatic purge

Hi,

Currently, we automatically purge the sessions table pwg_session_gc() in pwg_login(). It works fine but sometimes nobody logs in for months and Piwigo can be heavily visited in the meantime.

I have just encountered an example with 89k sessions in the table. The problem is that any operation on session takes a long time (slow SQL query).

I propose to add:

Code:

if (!isset($conf['session_last_purge']) or $conf['session_last_purge'] < time()-24*60*60)
{
  pwg_session_gc();
  conf_update_param('session_last_purge', time());
}

I know the config table is not the best place for such a cache data, but I have no better idea.

Offline

 

#2 2014-05-02 11:23:38

rvelices
Former Piwigo Team
2005-12-29
1960

Re: speed improvement, session automatic purge

I disagree. Php is supposed to do that
see session.gc_probability and session.gc_divisor in http://www.php.net/manual/fr/session.configuration.php

Unfortunately the php bundled with this lunux overwrites the gc_probility to 0 (don't understand the reason why), which means never purge sessions.
ini_set("session.gc_probability", 1) should be enough ...

Offline

 

#3 2014-05-02 11:24:27

rvelices
Former Piwigo Team
2005-12-29
1960

Re: speed improvement, session automatic purge

PS: on my .htaccess I have
php_value session.gc_probability 1

Offline

 

#4 2014-05-02 11:51:36

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13878

Re: speed improvement, session automatic purge

OK, I'll make some test on Piwigo.com (large scale ;-) and I'll tell you if it works fine.

Offline

 

#5 2014-05-02 21:10:02

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13878

Re: speed improvement, session automatic purge

I took a server on Piwigo.com, with 1k Piwigo on it.

Code:

ini_set("session.gc_probability", 100);

12h57, total = 2795946 sessions cumulated
13h05, total = 2141439 sessions cumulated
13h08, total = 1863132 sessions cumulated
13h10, total = 1818989 sessions cumulated
13h12, total = 1769286 sessions cumulated
13h16, total = 1568051 sessions cumulated
13h22, total = 1457432 sessions cumulated
13h27, total = 1373470 sessions cumulated
13h31, total = 1298089 sessions cumulated
13h35, total = 1088743 sessions cumulated
13h36, total = 1061625 sessions cumulated
13h42, total = 1053311 sessions cumulated
18h02, total = 351879  sessions cumulated
18h09, total = 350331  sessions cumulated
20h37, total = 275249  sessions cumulated
21h04, total = 237103  sessions cumulated

From 2.8M to 0.3M sessions cumulated.

So yes, it's a good solution (of course, 100 is a high, and the highest actually, value but I wanted quick results with less randomness)

Offline

 

#6 2014-05-03 10:26:50

matthys
Member
2014-04-02
188

Re: speed improvement, session automatic purge

Would like to make a note:

I just read something about session.gc_probability:
On Ubuntu 12.04 LTS it says “session.gc_probability = 0″ which is the correct setting. Normally it should be set to “1″, but on a Debian based setup that also has a cronjob in “/etc/cron.d/php5″ for cleaning up old session files it should be set to “0″.

I checked my Ubuntu 14.04 LTS server and indeed I got a cronjob called:
# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime)

Offline

 

#7 2014-05-03 11:50:50

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13878

Re: speed improvement, session automatic purge

Hi matthys,

I think this cronjob can't work for Piwigo because we use a specific database backend and not files for sessions.

Offline

 

#8 2014-05-16 13:16:18

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13878

Re: speed improvement, session automatic purge

After a few days of ini_set("session.gc_probability", 1) the sum of sessions for 1k Piwigo is approximately 270k (after a decrease to 30k when probability was 100, 10 days ago).

Offline

 
  •  » Engine
  •  » speed improvement, session automatic purge

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2025 · Contact