diff options
author | Joshua Lambert <joshua@gitlab.com> | 2017-03-16 18:45:46 +0000 |
---|---|---|
committer | Joshua Lambert <joshua@gitlab.com> | 2017-03-16 18:45:46 +0000 |
commit | d2f209a60b2ea2d889eaf5142c8d09ba0848a4c3 (patch) | |
tree | 62810ea2d1f8aa1d131e31ad667c39ea0a6d466a /doc/development/polling.md | |
parent | 83259875939958c6288066a3a4e59a5062b4c9e6 (diff) | |
parent | ce5d1b6fd7ed1aea2d2a675414ba81be624f2bf1 (diff) | |
download | gitlab-ce-29142-add-prometheus-integration-documentation.tar.gz |
Merge branch 'master' into '29142-add-prometheus-integration-documentation'29142-add-prometheus-integration-documentation
# Conflicts:
# doc/install/requirements.md
Diffstat (limited to 'doc/development/polling.md')
-rw-r--r-- | doc/development/polling.md | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/doc/development/polling.md b/doc/development/polling.md new file mode 100644 index 00000000000..a7f2962acf0 --- /dev/null +++ b/doc/development/polling.md @@ -0,0 +1,41 @@ +# Polling with ETag caching + +Polling for changes (repeatedly asking server if there are any new changes) +introduces high load on a GitLab instance, because it usually requires +executing at least a few SQL queries. This makes scaling large GitLab +instances (like GitLab.com) very difficult so we do not allow adding new +features that require polling and hit the database. + +Instead you should use polling mechanism with ETag caching in Redis. + +## How to use it + +1. Add the path of the endpoint which you want to poll to + `Gitlab::EtagCaching::Middleware`. +1. Implement cache invalidation for the path of your endpoint using + `Gitlab::EtagCaching::Store`. Whenever a resource changes you + have to invalidate the ETag for the path that depends on this + resource. +1. Check that the mechanism works: + - requests should return status code 304 + - there should be no SQL queries logged in `log/development.log` + +## How it works + +1. Whenever a resource changes we generate a random value and store it in + Redis. +1. When a client makes a request we set the `ETag` response header to the value + from Redis. +1. The client caches the response (client-side caching) and sends the ETag as + the `If-None-Match` header with every subsequent request for the same + resource. +1. If the `If-None-Match` header matches the current value in Redis we know + that the resource did not change so we can send 304 response immediately, + without querying the database at all. The client's browser will use the + cached response. +1. If the `If-None-Match` header does not match the current value in Redis + we have to generate a new response, because the resource changed. + +For more information see: +- [RFC 7232](https://tools.ietf.org/html/rfc7232) +- [ETag proposal](https://gitlab.com/gitlab-org/gitlab-ce/issues/26926) |