title: django tastypie performance tuning
body: <p>I have a site using django-tastypie to feed data to mobile apps through API. When doing a first apache-benchmark test to our API, I noticed the performance is not as good as I expected (have to admit that I don't have a solid base to support my expectation). My server setup is as following: 2.4GHZ 2-core CPU, 2560M memory, ubuntu12.04. I use nginx with uwsgi, setting uwsgi to use 4 workers, and nginx with 4 worker_processes as well.</p>
  
  <p>Here is my ab result from an API endpoint. The query is across 7 tables, with 30+ queries, and with a bunch of nested resources. When I profiled the SQL query, only 3 of them take more than 1ms (1ms, 1ms and 2ms, respectively). </p>
  
  <pre><code>ab -n 100 -c 8  -H 'Accept-Encoding: gzip'  "http://mysite"
  This is ApacheBench, Version 2.3 &lt;$Revision: 655654 $&gt;
  Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  Licensed to The Apache Software Foundation, http://www.apache.org/
  
  Benchmarking lvxingjia.cc (be patient).....done
  
  
  Server Software:        nginx/1.4.1
  Server Hostname:        mysite
  Server Port:            80
  
  Document Path:          mysite
  Document Length:        10807 bytes
  
  Concurrency Level:      8
  Time taken for tests:   19.146 seconds
  Complete requests:      100
  Failed requests:        0
  Write errors:           0
  Total transferred:      1117500 bytes
  HTML transferred:       1080700 bytes
  Requests per second:    5.22 [#/sec] (mean)
  Time per request:       1531.720 [ms] (mean)
  Time per request:       191.465 [ms] (mean, across all concurrent requests)
  Transfer rate:          57.00 [Kbytes/sec] received
  
  Connection Times (ms)
                min  mean[+/-sd] median   max
  Connect:       16   37  56.5     23     485
  Processing:   775 1455 238.1   1502    1901
  Waiting:      765 1443 237.8   1488    1889
  Total:        794 1492 235.7   1555    1920
  
  Percentage of the requests served within a certain time (ms)
    50%   1555
    66%   1626
    75%   1653
    80%   1694
    90%   1758
    95%   1783
    98%   1903
    99%   1920
   100%   1920 (longest request)
  </code></pre>
  
  <p>I'm pretty new to performance tuning and even don't want to bother doing it if it's not something terrible since we don't have too much traffic right now.</p>
  
  <p>So my first question is: is the number reasonable given my server resource and complexity of the request? </p>
  
  <p>My second question is if the number is unacceptable, which area should I look into to get improvement? DB queries, line-profiling django? I got the line-profiling result, actually see a tastypie issue with deepcopy, which had also been reported by other users, and the monky-patch does improve my performance by about 30%.</p>
  
  <p>I also see a great post here: <a href="https://stackoverflow.com/questions/14962289/bad-django-uwsgi-performance">Bad Django / uwsgi performance</a>, but I expect some opinion about my situation given my server/request scenario.</p>
  
  <p>Thanks!</p>