Skip to content

Instantly share code, notes, and snippets.

@shofetim
Created January 25, 2017 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shofetim/96ca70f086d9a5565c946b0f19244d8f to your computer and use it in GitHub Desktop.
Save shofetim/96ca70f086d9a5565c946b0f19244d8f to your computer and use it in GitHub Desktop.

Postgrest + Joyent performance test

I've created a repository with docker-compose configs for setting up Postgrest & PostgreSQL on Joyent & on Digital Ocean, and then benchmarked the instances. The Joyent config is here on the master branch: https://github.com/shofetim/postgrest-test/tree/master and the DigitalOcean config is here https://github.com/shofetim/postgrest-test/tree/digital-ocean on it's own branch.

Generally I've seen good performance from Joyent, but in this case, with Postgrest, something is just not right. The instance is almost immediately throttled for CPU usage.

You can use the configs above to setup your own instances, or use the instances I have running (I'll leave them up for a few days and then clean them up).

Starting two docker containers on Joyent Triton (one for PostgreSQL, on (512 MB) for Postgrest) and testing with Apache Benchmark:

ab -c 1 -n 100 'test.pgrest.svc.2c308c16-e36e-c2b5-b1c1-9d9b163f77e8.us-sw-1.triton.zone:3000/order?select=*,customer\{*\}&limit=10&offset=0'
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking test.pgrest.svc.2c308c16-e36e-c2b5-b1c1-9d9b163f77e8.us-sw-1.triton.zone (be patient).....done


Server Software:        postgrest/0.4.0.0
Server Hostname:        test.pgrest.svc.2c308c16-e36e-c2b5-b1c1-9d9b163f77e8.us-sw-1.triton.zone
Server Port:            3000

Document Path:          /order?select=*,customer\{*\}&limit=10&offset=0
Document Length:        154 bytes

Concurrency Level:      1
Time taken for tests:   248.929 seconds
Complete requests:      100
Failed requests:        0
Non-2xx responses:      100
Total transferred:      29300 bytes
HTML transferred:       15400 bytes
Requests per second:    0.40 [#/sec] (mean)
Time per request:       2489.288 [ms] (mean)
Time per request:       2489.288 [ms] (mean, across all concurrent requests)
Transfer rate:          0.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       41   42   1.6     42      52
Processing:    43 2447 3351.9     47   10751
Waiting:       43 2447 3351.9     47   10750
Total:         84 2489 3352.5     89   10792

Percentage of the requests served within a certain time (ms)
  50%     89
  66%   5752
  75%   6760
  80%   6803
  90%   6989
  95%   7970
  98%   8917
  99%  10792
 100%  10792 (longest request)

Note that half the requests take more than 5 seconds to complete, it takes 248 seconds to complete the test.

The same config, on a digital ocean 512 MB instance (this one running both PostgreSQL and PostgREST).

ab -c 1 -n 100 'http://104.236.170.73:3000/order?select=*,customer\{*\}&limit=10&offset=0'
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 104.236.170.73 (be patient).....done


Server Software:        postgrest/0.4.0.0
Server Hostname:        104.236.170.73
Server Port:            3000

Document Path:          /order?select=*,customer\{*\}&limit=10&offset=0
Document Length:        154 bytes

Concurrency Level:      1
Time taken for tests:   4.503 seconds
Complete requests:      100
Failed requests:        0
Non-2xx responses:      100
Total transferred:      29300 bytes
HTML transferred:       15400 bytes
Requests per second:    22.21 [#/sec] (mean)
Time per request:       45.030 [ms] (mean)
Time per request:       45.030 [ms] (mean, across all concurrent requests)
Transfer rate:          6.35 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       19   20   3.2     20      50
Processing:    22   25   4.5     23      58
Waiting:       21   24   4.5     23      57
Total:         41   45   5.4     43      77

Percentage of the requests served within a certain time (ms)
  50%     43
  66%     44
  75%     45
  80%     46
  90%     49
  95%     54
  98%     72
  99%     77
 100%     77 (longest request)

All the requests complete within 0.077 seconds, and it takes only 4.5 seconds for the entire test.

@shofetim
Copy link
Author

This was resolved, in the end the problem was that PostgREST was starting multiple threads per each available core, and it could see that there was 40+ cores on the machine, and so was starting 128 threads, which was very inefficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment