load balancing and php session data in memcached #164
brendankearney
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i have multiple web servers behind HAProxy and until recently, i was only able to really use one web server at a time. the load balancing algorithm was source based and sticky, so the same source IP would always hit the same web server. i was not syncing the session data between the web servers, or their php instances more accurately, and therefore ran into problems if i tried a least connections or round robin load balancing algorithm.
enter memcached... i installed memcached on each web server, configured it and started it. then i configured php and php-fpm to use the memcached instances on the localhost and the other web server. so webA would use itself and webB, while webB would use itself and webA. at first, some of my other php based apps were seeing improved performance, but would run into a session issue where no data for the session could be found. because memcached does not replicate data, session info was not always found when on web server could not find session data that was held in memcached on the other box. or so i think. anecdotal evidence seems to support this.
interestingly, i was getting odd errors about a failure to write the session data to memcached from pLA. in addition, i was getting the "frame within a frame within a frame" scenario that i think has been hummed and hawwed about. nearly every click that resulted in the body frame being populated resulted in the frame issue, and a message about configuration cache being stale and the configuration automatically being updated.
i moved the disparate instances from the web servers to a single instance on another server and pointed php and php-fpm on the web servers at the memcached instance on the other box. this cleared up the session issues because all data was within one instance and available to all calling clients. but, i still had issues in pLA with the error about failing to write the session data to memcached.
i looked in /var/lib/php/sessions/ and the file sizes range from 85 bytes to 1.6 MB. the largest of the files are all pLA session data. i looked into the configs for memcached, and by default the max-item-size is 1 MB. given the size of the session files on disk, i moved the max-item-size parameter in memcached to 5 MB and started testing.
the "frame within a frame within a frame" issue is gone and poking at everything i can, as much and as fast as i can does not reproduce the issue. i still get the configuration cache being stale error, but i can deal with that for now. i figured i would post my findings for anyone that wanted to scale up the pLA install on their network, but also to posit a theory about the frame issue.
i cannot find a setting in php that limits the size of something like session data, but there seems to be a correlation between the size of the session data and the frame issue. i hope this helps
Beta Was this translation helpful? Give feedback.
All reactions