From 589dbea9714ff8c3e8a9a029fb6aaff4a2f648f5 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 23 Apr 2018 17:07:41 +0100 Subject: [PATCH] Make Redis hold onto cached API responses longer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redis is giving us a big performance boost (it’s roughly halved the median request time on the admin app). Once we’re confident that it’s working properly[1] we can eke out a bit more performance from it by keeping the caches alive for longer. As far as I can tell we’re still using Redis in a very low-volume way[2], so increasing the number of things we’re storing shouldn’t start taxing our Redis server at all. But reducing the number of times we have to hit the API to refresh the cache _should_ result in some performance increase. --- 1. ie we’re not seeing instances of stale caches not being invalidated 2. We have 2.5G of available space in Redis. Here is our current usage: ``` used_memory:7728960 used_memory_human:7.37M used_memory_rss:7728960 used_memory_peak:16563776 used_memory_peak_human:15.79M used_memory_lua:37888 ``` --- app/notify_client/cache.py | 2 +- tests/app/notify_client/test_service_api_client.py | 10 +++++----- tests/app/notify_client/test_user_client.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/notify_client/cache.py b/app/notify_client/cache.py index 8bdd6e38c..85bcd54ab 100644 --- a/app/notify_client/cache.py +++ b/app/notify_client/cache.py @@ -4,7 +4,7 @@ from datetime import timedelta from functools import wraps from inspect import signature -TTL = int(timedelta(hours=24).total_seconds()) +TTL = int(timedelta(days=7).total_seconds()) def _get_argument(argument_name, client_method, args, kwargs): diff --git a/tests/app/notify_client/test_service_api_client.py b/tests/app/notify_client/test_service_api_client.py index ef4a9d318..77df78091 100644 --- a/tests/app/notify_client/test_service_api_client.py +++ b/tests/app/notify_client/test_service_api_client.py @@ -175,7 +175,7 @@ def test_client_returns_count_of_service_templates( call( 'service-{}'.format(SERVICE_ONE_ID), '{"data_from": "api"}', - ex=86400 + ex=604800, ) ], {'data_from': 'api'}, @@ -205,7 +205,7 @@ def test_client_returns_count_of_service_templates( call( 'template-{}-version-None'.format(FAKE_TEMPLATE_ID), '{"data_from": "api"}', - ex=86400 + ex=604800, ) ], {'data_from': 'api'}, @@ -235,7 +235,7 @@ def test_client_returns_count_of_service_templates( call( 'template-{}-version-1'.format(FAKE_TEMPLATE_ID), '{"data_from": "api"}', - ex=86400 + ex=604800, ) ], {'data_from': 'api'}, @@ -265,7 +265,7 @@ def test_client_returns_count_of_service_templates( call( 'service-{}-templates'.format(SERVICE_ONE_ID), '{"data_from": "api"}', - ex=86400 + ex=604800, ) ], {'data_from': 'api'}, @@ -295,7 +295,7 @@ def test_client_returns_count_of_service_templates( call( 'template-{}-versions'.format(FAKE_TEMPLATE_ID), '{"data_from": "api"}', - ex=86400 + ex=604800, ) ], {'data_from': 'api'}, diff --git a/tests/app/notify_client/test_user_client.py b/tests/app/notify_client/test_user_client.py index dc90413f7..9f5977f87 100644 --- a/tests/app/notify_client/test_user_client.py +++ b/tests/app/notify_client/test_user_client.py @@ -191,7 +191,7 @@ def test_client_converts_admin_permissions_to_db_permissions_on_add_to_service(a call( 'user-{}'.format(user_id), '{"data": "from api"}', - ex=86400 + ex=604800 ) ], 'from api',