Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Redis Session Handler #26

Closed
DaSourcerer opened this issue Feb 22, 2017 · 6 comments
Closed

Use Redis Session Handler #26

DaSourcerer opened this issue Feb 22, 2017 · 6 comments

Comments

@DaSourcerer
Copy link

As a redis server is already part of the infrastructure and the redis PHP extension is being installed anyways, it is probably a good idea to use it as a session storage as well. This will introduce no code changes and may help relieve the host system of i/o pressure. Per this example, the following configuration changes are needed:

session.save_handler = redis
session.save_path    = "tcp://127.0.0.1:6379?persistent=1"

This can be further improved by eliminating the TCP/IP overhead when using unix sockets directly:

session.save_path    = "unix:///var/run/redis/redis.sock?persistent=1"

With regards to #24, msgpack could be used as a session serialization format:

session.serialization_handler = msgpack

⚠️ Changing the serialization format will require clearing all sessions!

On a related note it may be worth investigating if the I/O scheduler on the host is adjusted correctly. By default, Linux is using the cfq scheduler which is intended for interactive tasks. Server and virtualized environments may profit from deadline (recommended for Amazon, btw) or even noop. The default is controlled by the elevator kernel parameter. Check the settings for existing devices with cat $(find /sys/devices/ -name scheduler).

@markharding
Copy link
Member

markharding commented Feb 22, 2017 via email

@DaSourcerer
Copy link
Author

Ah, didn't see that this class is in actual usage. Anyhow, is there a particular reason for keeping the sessions in Cassandra? FWIW, that is supposed to be volatile data.

@markharding
Copy link
Member

markharding commented Feb 22, 2017

I would disagree that sessions are volatile data for the server side. If a server had to be flushed then we'd log all of our users out and forget their sessions... not helpful! The sessions on cassandra have a ttl that matches the session so they do get purged when they cease to exist.

Cassandra is truly masterless, if one node dies the other 2 stay up and have that data.

We use Redis as a cache and we frequently clear it and make use for hot items, using redis as a session store would mean we'd need another redis system to be running that has disk storage. I'm certainly open to doing something like that in the future, but it would require a pretty substantial Redis cluster of its own to work well.

@DaSourcerer
Copy link
Author

Let me put it like this: You cannot assert the presence of a running session, can you? If one does not exist (or an existing one has been lost), one can easily be created. As sessions introduce state into the HTTP stack, logging the user in may be required. Granted, that is a bit of a nuisance, but also far from a desaster.

What I want to get at here is, I see session data at about the same data safety level than cache content. Therefore I see no issue saving session to disk only every n minutes or (depending on the application in question) hold them in memory entirely. That being said and given that random logouts on Minds are not unheard of, I would argue that a redis cluster is not strictly necessary.

Either way, I'm not going to argue any further here. I thought this were a cheap win, but my premise was wrong. Are you going to look into that I/O scheduler thing?

@markharding
Copy link
Member

At the client level I would agree they are disposable, but the server must always be able to detect a 'user' being there if they can show us their identity. Sessions are really important and can not be treated like caching data. Image if there was brief power outage of the session data and it wasn't hard stored; everyone would be logged out and would have to log back in again. This would have a massive impact on user engagement, our DAU, MAU and general user retention.

@markharding
Copy link
Member

The reason I mentioned needing another cluster was that the cache buffers do purge what is infrequently accessed, and when they do get full they start to throw things out, so we couldn't use sessions here as users would be thrown off repeatably without any warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants