title: How can I improve performance on my REST API?
body: <p>So I decided to benchmark my REST API today that I developed using Django REST Framework. The request I send is a GET request that basically retrieves the latest 50 posts from the database and returns it in JSON format.</p>
  
  <p>Using Apache Benchmark, the stats were:</p>
  
  <pre><code>Server Software: nginx/1.4.6
  Concurrency Level:      100
  Time taken for tests:   18.394 seconds
  Complete requests:      1000
  Failed requests:        0
  Non-2xx responses:      1000
  Total transferred:      5628000 bytes
  HTML transferred:       5447000 bytes
  Requests per second:    54.36 [#/sec] (mean)
  Time per request:       1839.442 [ms] (mean)
  Time per request:       18.394 [ms] (mean, across all concurrent requests)
  Transfer rate:          298.79 [Kbytes/sec] received
  
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:       17 1137 1899.3     31   12366
  Processing:    25  189 314.2     31    1418
  Waiting:       24  184 309.4     29    1415
  Total:         44 1326 1846.3    888   12407
  
  Percentage of the requests served within a certain time (ms)
    50%    888
    66%   1178
    75%   1775
    80%   2286
    90%   3434
    95%   4576
    98%   7859
    99%   7922
    100%  12407 (longest request)
  </code></pre>
  
  <p>This is obviously, incredibly slow...but I'm not sure how I can improve this.</p>
  
  <p>PS: I am very new to developing a server, and want to learn from this. In the above GET request, I am not doing any sort of threading whatsoever on the server side. All it simply is doing is:</p>
  
  <pre><code>    user_id = str(request.QUERY_PARAMS.get("user_id", None))
  
      cur = connection.cursor()
      cur.execute("SELECT * FROM get_posts(%s)", [user_id]) # This is a Function in the SQL database
  
      return Response(convertToDict(cursor))
  </code></pre>
  
  <p>I want to improve the speed of that GET request, so what can I possibly do to make it faster?</p>