I have 2 servers running each one instance of repcached. Php is configured to save sessions there.
The 2 servers are replicated for redundancy
The problem is that I am doing some benchmarks with ab. Running
ad -n 10000 -c 500 http://mysite
I am getting some err开发者_JS百科ors in the apache error log that failed to write session data
Looking at the listen_disabled_num at both servers it is 0, so no connections are not served
By the way I have max connections set to 4096
Any ideas?
Thanks
I've had this issue before when the session data was larger than Memcache's 1MB barrier. I solved it by compressing the session data before it was stored in Memcache.
Here's the code I'm using:
<?php
class SessionHandler {
public $lifeTime;
public function __construct() {
$this->lifeTime = intval(ini_get("session.gc_maxlifetime"));
session_set_cookie_params(0,"/",".domain.com",false,true);
session_name("SITESESSION");
session_set_save_handler(array (&$this,"open"),array (&$this,"close"),array (&$this,"read"),array (&$this,"write"),array (&$this,"destroy"),array (&$this,"gc"));
session_start();
}
public function open($savePath,$sessionName) {
return true;
}
public function close() {
return true;
}
public function read($sessionID) {
# The default miss for MC is (bool) false, so return it
return MC::get("userSession_{$sessionID}");
}
public function write($sessionID,$data) {
# This is called upon script termination or when session_write_close() is called, which ever is first.
return MC::set("userSession_{$sessionID}",$data,$this->lifeTime,true); # The last true sets it as compressed.
}
public function destroy($sessionID) {
# Called when a user logs out...
return MC::delete("userSession_{$sessionID}");
}
public function gc($maxlifetime) {
# The MC keys expire on their own, no need to do anything here.
return true;
}
}
?>
精彩评论