Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jackc/json_api_bench
Benchmark of Rails and PostgreSQL JSON generation techniques
https://github.com/jackc/json_api_bench
Last synced: 9 days ago
JSON representation
Benchmark of Rails and PostgreSQL JSON generation techniques
- Host: GitHub
- URL: https://github.com/jackc/json_api_bench
- Owner: jackc
- Created: 2013-01-22T00:50:40.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-05-26T18:56:28.000Z (over 2 years ago)
- Last Synced: 2024-10-14T21:58:08.138Z (23 days ago)
- Language: Ruby
- Size: 72.3 KB
- Stars: 33
- Watchers: 6
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: readme.markdown
Awesome Lists containing this project
README
# JSON API Benchmark
This application is a sample benchmark for various approaches to generating JSON API responses. It was written to accompany [this post](http://blog.hashrocket.com/posts/faster-json-generation-with-postgresql) about PostgreSQL JSON generation on the [Hashrocket blog](http://blog.hashrocket.com/). It exercises the entire application stack instead of just JSON generation so that the timing can be viewed in the context of the entire application. It uses unicorn with 4 worker processes. It typically tests three approaches:
* Standard Rails - to_json on model objects
* Optimized Rails - pluck and select_all
* PostgreSQL - row_to_json and array_to_jsonThe sample domain is a simple dictionary. The entities involved are words, definitions, quotes, and related words.
# Requirements
PostgreSQL, siege
# Scenarios
* Concise auto-complete word search - Returns first 10 words matching search term. This scenario is an example of a very simple, feather weight API call that returns only an array of 10 strings.
* Rich auto-complete word search - Returns first 10 words matching search term with text, pronunciation, part of speech, and first definition. This is a light weight example that involves two entity types.
* Word definition - Shows the definitions, quotes, and related words for the specified word. This is a middle weight example.
* Many word definitions - Shows the definitions, quotes, and related words for many words at a time. This is representative of a heavy weight JSON API.# Running the Benchmarks
Bundle dependencies:
bundle install
To setup the test data run the following rake tasks:
rake db:create db:migrate benchmark:setup
Start the server:
RAILS_ENV=production unicorn -c config/unicorn.rb
Run the benchmark rake task:
rake benchmark:run