I am running a python application (flask + redis-py) with uwsgi + nginx and using aws elasticache (redis 2.8.24).
trying to improve application response time, I noticed that under high load (500 requests per second / for 30 seconds using loader.io) I lose requests (for this test I use only one server without load balancing, 1 instance of uwsgi, 4 process intended for testing). 
I went deeper and found out that under this download some requests to ElastiCache are slow. eg:
- normal load: cache_set time 0.000654935836792
- heavy load: cache_set time 0.0122258663177 this does not happen for all requests, it just happens by accident.
My AWS ElastiCache is based on 2 nodes on cache.m4.xlarge (AWS default configuration settings). See current clients connected in the last 3 hours: 
I think this does not make sense since there are currently 14 servers (8 of them with high traffic XX RPS use this cluster), I expect to see a much higher client speed.
UWSGI configuration (version 2.0.5.1)
processes = 4 enable-threads = true threads = 20 vacuum = true die-on-term = true harakiri = 10 max-requests = 5000 thread-stacksize = 2048 thunder-lock = true max-fd = 150000 # currently disabled for testing #cheaper-algo = spare2 #cheaper = 2 #cheaper-initial = 2 #workers = 4 #cheaper-step = 1
Nginx is just a web proxy for uWSGI using a unix socket.
This is how I open a connection with redis:
rdb = [ redis.StrictRedis(host='server-endpoint', port=6379, db=0), redis.StrictRedis(host='server-endpoint', port=6379, db=1) ]
This is how I set the value, for example:
def cache_set(key, subkey, val, db, cache_timeout=DEFAULT_TIMEOUT): t = time.time() merged_key = key + ':' + subkey res = rdb[db].set(merged_key, val, cache_timeout) print 'cache_set time ' + str(time.time() - t) return res cache_set('prefix', 'key_name', 'my glorious value', 0, 20)
This is how I get the value:
def cache_get(key, subkey, db, _eval=False): t = time.time() merged_key = key + ':' + subkey val = rdb[db].get(merged_key) if _eval: if val: val = eval(val) else:
Version:
- uWSGI: 2.0.5.1
- Flask: 0.11.1
- redis-py: 2.10.5
- Redis: 2.8.24
So conclude:
- Why AWS clients are considered low if 14 servers are connected, each of which has 4 processes, and each of them opens a connection to 8 different databases in a redis cluster
- What makes query response times rise?
- Would thank for any recommendations regarding ElastiCache and / or uWSGI performance under heavy load