[PYTHON] Redis performance measurement

-* The security software was bad, so I measured it again.

--I tried calling Redis from Flask on my Mac. --redis, flask and apachebench are all running on the same machine.

Write process

--5000 times at 100 at the same time ... Fast 11msec

sh-3.2$ ab -n5000 -c100 -r "http://127.0.0.1/set"
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software:        Apache/2.4.25
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /set
Document Length:        201 bytes

Concurrency Level:      100
Time taken for tests:   0.595 seconds
Complete requests:      5000
Failed requests:        0
Non-2xx responses:      5000
Total transferred:      1895000 bytes
HTML transferred:       1005000 bytes
Requests per second:    8403.46 [#/sec](mean)
Time per request:       11.900 [ms](mean)
Time per request:       0.119 [ms](mean, across all concurrent requests)
Transfer rate:          3110.27 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       3
Processing:     1   11   3.4     11      21
Waiting:        1   11   3.4     11      21
Total:          4   12   3.5     12      21

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     13
  75%     14
  80%     15
  90%     16
  95%     17
  98%     19
  99%     20
 100%     21 (longest request)

--10000 times at 100 at the same time ... Fast 15msec

sh-3.2$ ab -n10000 -c100 -r "http://127.0.0.1/set"
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.4.25
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /set
Document Length:        201 bytes

Concurrency Level:      100
Time taken for tests:   1.475 seconds
Complete requests:      10000
Failed requests:        0
Non-2xx responses:      10000
Total transferred:      3790000 bytes
HTML transferred:       2010000 bytes
Requests per second:    6777.55 [#/sec](mean)
Time per request:       14.755 [ms](mean)
Time per request:       0.148 [ms](mean, across all concurrent requests)
Transfer rate:          2508.49 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      24
Processing:     1   14   5.2     15      47
Waiting:        1   14   5.2     15      47
Total:          4   15   5.4     15      48

Percentage of the requests served within a certain time (ms)
  50%     15
  66%     17
  75%     18
  80%     19
  90%     20
  95%     21
  98%     22
  99%     24
 100%     48 (longest request)

Read process

――5000 times at 100 at the same time ... It's fast! 11msec

sh-3.2$ ab -n5000 -c100 -r "http://127.0.0.1/get"
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software:        Apache/2.4.25
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /get
Document Length:        201 bytes

Concurrency Level:      100
Time taken for tests:   0.556 seconds
Complete requests:      5000
Failed requests:        0
Non-2xx responses:      5000
Total transferred:      1895000 bytes
HTML transferred:       1005000 bytes
Requests per second:    9000.20 [#/sec](mean)
Time per request:       11.111 [ms](mean)
Time per request:       0.111 [ms](mean, across all concurrent requests)
Transfer rate:          3331.13 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.3      1       3
Processing:     1   10   3.5     10      19
Waiting:        1   10   3.4     10      19
Total:          3   11   3.7     11      20

Percentage of the requests served within a certain time (ms)
  50%     11
  66%     13
  75%     14
  80%     14
  90%     16
  95%     17
  98%     18
  99%     19
 100%     20 (longest request)

--Simultaneous 200 and 5000 times ... Error orz

sh-3.2$ ab -n5000 -c200 "http://127.0.0.1/get"
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
apr_socket_recv: Connection reset by peer (54)

--10000 times with 100 at the same time ... It works with 100 at the same time.

sh-3.2$ ab -n10000 -c100 "http://127.0.0.1/get"
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.4.25
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /get
Document Length:        201 bytes

Concurrency Level:      100
Time taken for tests:   1.339 seconds
Complete requests:      10000
Failed requests:        0
Non-2xx responses:      10000
Total transferred:      3790000 bytes
HTML transferred:       2010000 bytes
Requests per second:    7467.42 [#/sec](mean)
Time per request:       13.392 [ms](mean)
Time per request:       0.134 [ms](mean, across all concurrent requests)
Transfer rate:          2763.82 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.6      1      11
Processing:     1   12   4.3     11      22
Waiting:        1   12   4.3     11      22
Total:          3   13   4.8     12      23

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     15
  75%     17
  80%     19
  90%     20
  95%     22
  98%     22
  99%     22
 100%     23 (longest request)

Reference: Empty processing

――Measure the speed when nothing is done (the speed only for Flask). ――It is 13msec.

sh-3.2$ ab -n10000 -c100 -r "http://127.0.0.1/"
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.4.25
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /
Document Length:        1799 bytes

Concurrency Level:      100
Time taken for tests:   1.354 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      20460000 bytes
HTML transferred:       17990000 bytes
Requests per second:    7387.12 [#/sec](mean)
Time per request:       13.537 [ms](mean)
Time per request:       0.135 [ms](mean, across all concurrent requests)
Transfer rate:          14759.82 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.8      1      14
Processing:     1   12   3.8     12      30
Waiting:        1   12   3.8     12      30
Total:          3   13   4.2     14      32

Percentage of the requests served within a certain time (ms)
  50%     14
  66%     15
  75%     16
  80%     17
  90%     19
  95%     19
  98%     23
  99%     27
 100%     32 (longest request)

Error in Apache Bench ...

--Apart from performance, apache bench itself seems to cause an error. ――When you google, it's fine, why? ?? ??

Test program

――This is the program used for this test.

app.py


import os
import sys
import redis
import random
from flask import Flask
from datetime import datetime as dt

app = Flask(__name__)

#If it is in the connection path or environment variable, it has priority
REDIS_URL = os.environ.get('REDIS_URL') if os.environ.get(
    'REDIS_URL') != None else 'redis://localhost:6379'
#Database specification
DATABASE_INDEX = 1  #Dare 1 instead of 0
#Get one from the connection pool
pool = redis.ConnectionPool.from_url(REDIS_URL, db=DATABASE_INDEX)
#Use connection
r = redis.StrictRedis(connection_pool=pool)

@app.route('/')
def root():
    return '{"status":"OK"}'

@app.route('/get')
def get():
    n = random.randrange(len(r.keys()))
    key = r.keys()[n]
    return str(r.get(key))

@app.route('/set')
def set():
    tdatetime = dt.now()
    key = tdatetime.strftime('%Y-%m-%d %H:%M:%S')
    r.set(key, {'val': key})
    return '{"action":"set"}'

if __name__ == '__main__':
    app.run()

Recommended Posts

Redis performance measurement
NVMe Performance Measurement Summary
Network performance measurement with iperf
Web application performance measurement tool Funkload ...
Transpose CSV file in Python Part 2: Performance measurement