Skip to content

Improve Redis doc for 2.x to avoid common pitfalls #418

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

Merged
merged 11 commits into from
Nov 6, 2018

Conversation

andrerom
Copy link
Contributor

@andrerom andrerom commented Oct 9, 2018

Question Answer
JIRA Ticket
Versions 2.x + master

Updates / Appends Redis doc across Session, Clustering, persistence cache, performance and troubleshooting doc, to try to cover some issues Partners and Community members have been running into over the last few months.

Todo:


## Redis: Session are removed or new sessions are refused

See info on [Redis in session doc](../guide/session.md); Ideally use an unique instance of Redis for sessions, that either never runs of of memory or uses an eviction policy that suites your needs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separated instance perhaps? Sounds more natural for me.

Nitpics:
an unique -> a unique
runs of of memory -> run out of memory
suites -> suits

@@ -31,8 +20,8 @@ Notes:

- `UrlWildCardHandler` is not currently cached
- Currently in case of transactions this is handled very simply by clearing all cache on rollback, this can be improved in the future if needed.
- Some tree/batch operations will cause clearing all persistence cache, this will be improved in the future when we change to a cache service cable of cache tagging.
- Search is not defined as Persistence and the queries themselves are not planned to be cached. Use [Solr](solr.md) which does this for you to improve scale and offload your database.
- [Cache tagging](https://symfony.com/doc/current/components/cache/cache_invalidation.html#using-cache-tags) is used in order to allow clearing cache by alternative indexes, for instance tree operations or changes to content types are examples of operations that also needs to invalidate content cache by tags.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpic:

needs -> need

@@ -70,7 +59,7 @@ ezpublish:
# "site_group" refers to the group configured in site access
site_group:
# cache_pool is set to '%env(CACHE_POOL)%'
# env(CACHE_POOL) is set to 'cache.app'
# env(CACHE_POOL) is set to 'cache.app', a symfony service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you mentioned it, it's not obvious for everyone 👍

WDYT about a symfony service -> a Symfony service, for examples see app/config/cache_pool/*

@@ -108,7 +97,23 @@ services:

##### Redis Cluster

It is possible to set up and use Redis as a cluster. This configuration is more efficient and reliable for large installations. Redis Cluster can be configured in two ways, the first using [create-cluster script](https://redis.io/topics/cluster-tutorial) and the second using [Redis Sentinel](https://redis.io/topics/sentinel). If you use Platform.sh Enterprise you can benefit from the Redis Sentinel across three nodes for greater fault tolerance. Platform.sh Professional and lower versions offer Redis in single instance mode only. Configuration on eZ Platform / Symfony stays the same regardless of the Redis version, single instance mode or cluster mode.
Configuration of several Redis instances can be done in several ways, as Persistence cache depends on all involved web servers seeing the same view of the cache as it's shared, the following applies:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:
Configuration -> The configuration

As for me this sentence is a little bit too complicated, WDYT about putting it like this:

Configuration of several Redis instances can be done in several ways. Persistence cache depends on all involved web servers, each of them seeing the same view of the cache because it's shared among them. The following configurations are possible:

It is possible to set up and use Redis as a cluster. This configuration is more efficient and reliable for large installations. Redis Cluster can be configured in two ways, the first using [create-cluster script](https://redis.io/topics/cluster-tutorial) and the second using [Redis Sentinel](https://redis.io/topics/sentinel). If you use Platform.sh Enterprise you can benefit from the Redis Sentinel across three nodes for greater fault tolerance. Platform.sh Professional and lower versions offer Redis in single instance mode only. Configuration on eZ Platform / Symfony stays the same regardless of the Redis version, single instance mode or cluster mode.
Configuration of several Redis instances can be done in several ways, as Persistence cache depends on all involved web servers seeing the same view of the cache as it's shared, the following applies:
- [Redis Cluster](https://redis.io/topics/cluster-tutorial)
- Shards cache across several instances in order to be able to cache more then memory of one server allows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

then -> than a

# But in order to use %ezplatform.session.save_path%, default eZ Platform instead sets %ezplatform.session.handler_id% to:
# - session.handler.native_file (default)
# - ezplatform.core.session.handler.native_redis (recommended value for Cluster usage, using php-redis session handler )
handler_id: '%ezplatform.session.handler_id%'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see that in the docs 👍

For a [cluster](clustering.md) setup you need to configure sessions to use a back end that is shared between web servers and supports locking.
The only options out of the box supporting this in Symfony are the native PHP Memcached session save handler
provided by the `php-memcached` extension, and Symfony session handler for PDO (database).
For a [cluster](clustering.md) setup you need to configure sessions to use a back end that is shared between web servers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

back end -> backend (?)

##### Storing sessions in Redis using `php-redis`

To set up eZ Platform using the [Redis](https://pecl.php.net/package/redis)
you need to [configure the session save handler settings in `php.ini`](https://github.com/phpredis/phpredis#php-session-handler),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, it's enough to configure it only on eZ (Symfony) side without touching php.ini configuration.

Copy link
Contributor Author

@andrerom andrerom Oct 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but if they need to configure anything which falls outside the save path DSN, they do need to configure php.ini right? /cc @vidarl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have an example here https://labs.madisoft.it/scaling-symfony-sessions-with-redis/ So yes you need to provide a DSN
Configuring php.ini means that all your PHP project will use redis. It might not be something you want to do if you share many project on the same server. (or use php_value on vhost by example)

Copy link
Contributor Author

@andrerom andrerom Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah updated PR text show both ways now, both the way of using what php provides, and the way of using own handler. Both on memcached and redis. And on redis it's what we do by default on platform.sh.

and set and set eZ Platform's `%ezplatform.session.handler_id%` to `ezplatform.core.session.handler.native_redis`.

Furthermore when using Redis for sessions make sure to:
- Either use load balancer with session afiinity, or only Read/write to one Redis instance at a time. _See [Redis Cluster with persistance cache](persistence_cache.md) for furhter info_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Read/write -> read/write

- Ideally keep [persistance cache](persistence_cache.md) and session data seperated:
- Sessions can not risk getting [randomly evicted](https://redis.io/topics/lru-cache#eviction-policies) when you run out of memory for cache.
- And you can not disable eviction either, as Redis will then start to refuse new entries once full, including new sessions.
- If you want to make sure sessions survive Redis or Server restarts, consider using persistant Redis instance for Sessions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

persistant -> persistent

@andrerom andrerom changed the title [RFC] Improve Redis doc for 2.x to avoid common pitfalls Improve Redis doc for 2.x to avoid common pitfalls Oct 29, 2018
@andrerom
Copy link
Contributor Author

@kmadejski and @dspe PR updated, please have a look to see if it fits your views on this :)


- Memcached/Redis can in some cases perform better then filesystem cache even with a single server, as it offers better general performance for operations invalidating cache.
- However, pure read performance is slower, especially if the next points is not optimized.
- With cache being on different node(s) then web server, make sure to try to tune latency between the two.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"then" => "than" ?


##### Storing sessions in Redis using pecl package
To set up eZ Platform using the [Redis](https://pecl.php.net/package/redis)
you need to set eZ Platform's `%ezplatform.session.handler_id%` to `ezplatform.core.session.handler.native_redis`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is not completely correct. Unless you are on Platform.sh you also may configure redis using php.ini settings.
On platform.sh however, you must use ezplatform.core.session.handler.native_redis ( as you don't know the redis configuration at commit/build time )

@andrerom
Copy link
Contributor Author

@vidarl / @kmadejski section on configuring redis / memcached is rewritten.

- Redis is recommended over filesystem cache even with a single server, as it offers better general performance for operations invalidating cache.
- However, pure read performance is slower, especially if the next point is not optimized.
- If you use Redis, make sure to tune it for in-memory cache usage. Its persistence feature is not needed with eZ Platform cache and will severely slow down execution time.
### Memcached/Redis
Copy link
Contributor Author

@andrerom andrerom Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc review note: this moves the header / anchor back to what it was, and afaik still is in 1.13 doc

@andrerom andrerom deleted the v2_improve_redis_doc branch November 6, 2018 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants