Faster api #2346

Merged
merged 3 commits into from Jul 3, 2015

Projects

None yet

3 participants

@nickstenning
Member

The stream atom feed is currently timing out in production. There is a bunch of different stuff going on here (including the fact that the atom feed makes requests to our API by going out to the public internet and back in rather than directly to the service running on the same host...) but benchmarking suggests that the two biggest sources of slowness are:

  1. JSON serialisation (specifically "pretty" output)
  2. Making two identical queries to ElasticSearch instead of one...

In addition, I think 1000 annotations in the atom feed is probably a bit much -- an atom feed approaching a megabyte seems excessive. I've dropped the default number of annotations to 100.

With these three changes we go from about 1 request per second...

$ wrk -c1 -d10s -t1 'http://localhost:5000/stream.atom'
Running 10s test @ http://localhost:5000/stream.atom
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   727.94ms   31.91ms 772.22ms   53.85%
    Req/Sec     1.00      0.00     1.00    100.00%
  13 requests in 10.09s, 10.79MB read
Requests/sec:      1.29
Transfer/sec:      1.07MB

...to about 13:

$ wrk -c1 -d10s -t1 'http://localhost:5000/stream.atom'
Running 10s test @ http://localhost:5000/stream.atom
  1 threads and 1 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    71.99ms   17.25ms 159.24ms   95.10%
    Req/Sec    13.58      5.06    20.00     57.29%
  139 requests in 10.03s, 12.61MB read
Requests/sec:     13.86
Transfer/sec:      1.26MB
@landscape-bot

Code Health
Code quality remained the same when pulling 0b8724a on hypothesis:faster-api into c6be6c1 on hypothesis:master.

@tilgovi tilgovi commented on an outdated diff Jul 3, 2015
@@ -97,7 +97,7 @@ def create_api(global_config, **settings):
config.set_authorization_policy(acl_authz)
config.set_root_factory('h.api.resources.create_root')
- config.add_renderer('json', JSON(indent=4))
+ config.add_renderer('json', JSON())
@tilgovi
tilgovi Jul 3, 2015 Contributor

You can just remove this line then. The 'json' renderer is a default and I was just overriding it here.

@tilgovi
Contributor
tilgovi commented Jul 3, 2015

Other than my comment about the 'json' renderer this is great. Merge it after you fix that.

@tilgovi
Contributor
tilgovi commented Jul 3, 2015

Never mind. I've got it.

nickstenning added some commits Jul 3, 2015
@nickstenning @tilgovi nickstenning Lower default and maximum "limit" params for Atom feed
With a default timeout of 200ms for the API Client, retrieving and
parsing JSON for that many annotations takes too long.
701a58f
@nickstenning @tilgovi nickstenning Don't indent API output
This is an interface for machines, not humans. This results in a factor
of >2 speedup for large query sets:

Before:

    $ wrk -c1 -d10s -t1 'http://localhost:5000/api/search?limit=1000'
    Running 10s test @ http://localhost:5000/api/search?limit=1000
      1 threads and 1 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency   340.54ms   38.82ms 446.64ms   75.86%
        Req/Sec     2.62      0.49     3.00     62.07%
      29 requests in 10.08s, 88.02MB read
    Requests/sec:      2.88
    Transfer/sec:      8.74MB

After:

    $ wrk -c1 -d10s -t1 'http://localhost:5000/api/search?limit=1000'
    Running 10s test @ http://localhost:5000/api/search?limit=1000
      1 threads and 1 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency   167.97ms   25.03ms 223.00ms   69.49%
        Req/Sec     6.31      2.71    10.00     69.49%
      59 requests in 10.04s, 96.15MB read
    Requests/sec:      5.87
    Transfer/sec:      9.57MB
4542a2f
@nickstenning @tilgovi nickstenning Don't make two queries when one will do.
The search function doesn't need to make two calls when one will do.
f45d379
@tilgovi tilgovi merged commit 3b1113b into master Jul 3, 2015

0 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
@tilgovi tilgovi deleted the faster-api branch Jul 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment