Files
2012-02-21 01:15:00 -05:00

1 line
7.9 KiB
JSON

[{"user_id": 1339, "stars": [], "topic_id": 20699, "date_created": 1303394612.2166109, "message": "I'm wondering what is the normal number of SQL queries per page. Any idea? I'm DJDT and some of page queries > 50.", "group_id": 81, "id": 770354}, {"user_id": 7, "stars": [{"date_created": 1303407958.9573841, "user_id": 1}, {"date_created": 1303418559.0533371, "user_id": 927}], "topic_id": 20699, "date_created": 1303398495.380152, "message": "really the numbers don't matter as much as what the performance looks like", "group_id": 81, "id": 771104}, {"user_id": 7, "stars": [], "topic_id": 20699, "date_created": 1303398483.003062, "message": "Under 10 is a reasonable target for common pages", "group_id": 81, "id": 771101}, {"user_id": 7, "stars": [], "topic_id": 20699, "date_created": 1303398511.056272, "message": "so 5 queries with 10 complex joins apiece are worse than 20 simple get by pks", "group_id": 81, "id": 771110}, {"user_id": 1339, "stars": [], "topic_id": 20699, "date_created": 1303404899.344084, "message": "@alex Does the query time has any significant impact on performance? Or which one is more important, no. of queries vs time.", "group_id": 81, "id": 772890}, {"user_id": 1339, "stars": [], "topic_id": 20699, "date_created": 1303407533.282594, "message": "@sivictor Any idea on the reasonable query time? My current dev setup produce 50ms or less. Wondering if that is ok.", "group_id": 81, "id": 773398}, {"user_id": 26100, "stars": [], "topic_id": 20699, "date_created": 1303406951.6246331, "message": "@matthewphiong Query time will directly effect the responsiveness of your project. In some cases you can gain performance by using more, but simpler, queries.", "group_id": 81, "id": 773284}, {"user_id": 7, "stars": [{"date_created": 1303420156.3096061, "user_id": 9896}, {"date_created": 1303452500.65362, "user_id": 1339}], "topic_id": 20699, "date_created": 1303412372.537708, "message": "@matthewphiong 50ms is fine, be sure to look at numbers on a real server though, your laptop will often be beefier than the VPS you'll deploy on :)", "group_id": 81, "id": 774317}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303436016.203742, "message": "(Oh, and 3ms refers to production query times, the local server our slowest queries around sub 100ms though)", "group_id": 81, "id": 777303}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303435980.4414589, "message": "do you have unnecessary joins?", "group_id": 81, "id": 777291}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303435973.683533, "message": "are your queries slow?", "group_id": 81, "id": 777289}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303435982.001354, "message": "etc.", "group_id": 81, "id": 777292}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303435962.8093951, "message": "On heavy pages we have 20-25 (but they're very very efficient, less than 3ms for almost every single one). We also do client side joins, which adds extra queries. In general, our bare minimum is around 5 queries (uncached), and most dynamic pages have around 10.", "group_id": 81, "id": 777282}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303435966.5730751, "message": "Your goal should be to measure the usefulness of those queries:", "group_id": 81, "id": 777284}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303435967.411552, "message": "are you hitting the same table for different values based on the same filter over and over?)", "group_id": 81, "id": 777285}, {"user_id": 1339, "stars": [], "topic_id": 20699, "date_created": 1303452773.4586439, "message": "@zeeg @sivictor @alex Thanks :)", "group_id": 81, "id": 779469}, {"user_id": 13912, "stars": [], "topic_id": 20699, "date_created": 1303457612.7319081, "message": "on a more complex page with many template tags that hit the database it may be normal to have more than 10 or 20. Just be careful because django makes it easy to execute many queries for something you don't have to.", "group_id": 81, "id": 779723}, {"user_id": 13912, "stars": [{"date_created": 1303485134.8070569, "user_id": 275}], "topic_id": 20699, "date_created": 1303457440.471885, "message": "seeing >10 queries in JDJT I usually suspect queries executing in each iteration in a loop somewhere in a template", "group_id": 81, "id": 779715}, {"user_id": 13912, "stars": [{"date_created": 1303485129.7170129, "user_id": 275}, {"date_created": 1303488475.682637, "user_id": 1127}, {"date_created": 1303495664.8330541, "user_id": 1339}, {"date_created": 1304124690.7196031, "user_id": 14070}], "topic_id": 20699, "date_created": 1303457457.6003871, "message": "which is most often because I forgot select_related somewhere", "group_id": 81, "id": 779718}, {"user_id": 1339, "stars": [], "topic_id": 20699, "date_created": 1303495687.405241, "message": "@Vasil Great pointer. select_related really does help bringing down the # queries.", "group_id": 81, "id": 783594}, {"user_id": 1147, "stars": [], "topic_id": 20699, "date_created": 1303511420.8050759, "message": "And then there's NoSQL :) Off-topic?", "group_id": 81, "id": 785721}, {"user_id": 1147, "stars": [{"date_created": 1303511437.4793971, "user_id": 1}], "topic_id": 20699, "date_created": 1303511362.5049591, "message": "Generally less queries is better. Splitting off a large query into many smaller ones and having it total less time is possible although I would say that's an exception. Generally it's better to pull everything you need at one time as long as you REALLY need it. Don't join 8 models together all the time when you only use a couple. ORMs are notorious for spitting out huge number of queries if you don't know what to look for. select_related is a great start. A huge number of columns in a model can also be a problem on a very busy model. Especially if you only use 1 or 2 of the columns most of the time. One to one relationships can help there.", "group_id": 81, "id": 785710}, {"user_id": 594, "stars": [], "topic_id": 20699, "date_created": 1303532005.3112969, "message": "And cache everything. Seriously. Most of your queries don't need to update extremely often. Make sure that users who aren't logged in make few to no queries, and users who are logged in only hit the parts of the database that have changed since they last loaded the page.", "group_id": 81, "id": 787174}, {"user_id": 1127, "stars": [{"date_created": 1303542376.3160551, "user_id": 1339}, {"date_created": 1303856610.2002549, "user_id": 2341}, {"date_created": 1303969337.3861971, "user_id": 4936}], "topic_id": 20699, "date_created": 1303533687.1338749, "message": "A neat trick to help with caching is something we've done on Disqus: we actually set a cookie on each request with the current authenticated users information. We use this to render the \"logged in\" state, and we do an asynchronous request to keep that updated. Assuming a large chunk of your website can be loaded asyncrhonously (especially commonly hit pages) or doesnt change between users, this then makes it so you can use a reverse proxy extremely effectively http://dpaste.com/534865/", "group_id": 81, "id": 787248}, {"user_id": 1127, "stars": [{"date_created": 1303843841.084811, "user_id": 26100}, {"date_created": 1303856641.4300261, "user_id": 2341}, {"date_created": 1303860003.099071, "user_id": 2588}], "topic_id": 20699, "date_created": 1303843400.399734, "message": "Something else we whipped up for logging queries which are executing while rendering templates: https://gist.github.com/942761", "group_id": 81, "id": 817547}, {"user_id": 31418, "stars": [], "topic_id": 20699, "date_created": 1303945812.893548, "message": "@zeeg what if I set is_staff in that cookie myself? :)", "group_id": 81, "id": 833927}, {"user_id": 1127, "stars": [], "topic_id": 20699, "date_created": 1303948405.8299179, "message": "@dgerzo your navigation might show something different, but that's it (server side checks still exist) :)", "group_id": 81, "id": 834222}]