YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Performance optimisation with GraphQL

Optimising response times with GraphQLan experiment with MongoDB and ElasticSearch

(These slides were adapted to be suitable offline)

Page 2: Performance optimisation with GraphQL

Intuitions: GraphQL faster

• less requests

• smaller responses

Page 3: Performance optimisation with GraphQL

Reality Eats Intuitions

for Breakfast

Page 4: Performance optimisation with GraphQL

Not obvious• Client has to send more info

• query contains list of fields

• -> biggest requests payloads

• Server has more work to do

• query validation

• customise response

Page 5: Performance optimisation with GraphQL

Do not guess it,

test it

Page 6: Performance optimisation with GraphQL

–A client

“I want the id and the versions of all products”

Page 7: Performance optimisation with GraphQL

30000 50000 100000

MongoDB ES

Perf of REST endpoints

Page 9: Performance optimisation with GraphQL

Client App Server

Data storage

Optimisation between client and application server

Page 10: Performance optimisation with GraphQL

30000 50000 100000

MongoDB ES MongoDB GraphQL ES GraphQL

Page 11: Performance optimisation with GraphQL

• smallest responses -> better performances

• difference not as important as expected

Page 12: Performance optimisation with GraphQL

Client App Server

Data storage

Optimisation between application server and data storage

Page 13: Performance optimisation with GraphQL

select * from products;

select id, version from products;

Optimise DB queries

Page 14: Performance optimisation with GraphQL

http://sangria-graphql.org/learn/#projections

Page 15: Performance optimisation with GraphQL

In Mongo

db .getCollection('products') .find({})

db .getCollection('products') .find({}, {_id: 1, version: 1})

Page 16: Performance optimisation with GraphQL

30000 50000 100000

Mongo Mongo GraphQL Mongo GraphQL projections

Page 17: Performance optimisation with GraphQL

In Elasticsearch{ "_source": true, "query" : […]}

{ "_source": [ "id", "version"], "query" : […]}

Page 18: Performance optimisation with GraphQL

30000 50000 100000

ES ES GraphQL ES GraphQL projections

Page 19: Performance optimisation with GraphQL

30000 50000 100000

Mongo ESMongo GraphQL projections ES GraphQL projections

Page 20: Performance optimisation with GraphQL

• Optimising database queries have an important impact on performances

• GraphQL allows to optimise from client to data storage

Page 21: Performance optimisation with GraphQL

• Tested use-case intentionally picked to be favorable to GraphQL (test assumption)

• Test yourself for your use-case

• Should not choose GraphQL primary for performances but for features

Page 22: Performance optimisation with GraphQL

Further optimisations

• Pre-computed queries

• client sends only values of variables

• queries already validated

• Binary serialisation format


Related Documents