<div dir="ltr"><div dir="ltr"><span class="gmail-im" style="color:rgb(80,0,80)"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><span style="font-family:arial,helvetica,sans-serif">If it transfers 2 gigabyte of data, then this single postgres query is going to take some time.</span></div></div></div></blockquote><div><br></div></span><div>Of course, but this is not the case. Data is a very small packet.</div><span class="gmail-im" style="color:rgb(80,0,80)"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div style="font-family:arial,helvetica,sans-serif">If someone is doing updates which require a full table lock on the users table, this query is going to take some time.</div></div></div></blockquote><div><br></div></span><div>No locks, read only: “select * from users where id = ‘123’”. Writes are on user registration only, so irrelevant.</div><span class="gmail-im" style="color:rgb(80,0,80)"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><span style="font-family:arial,helvetica,sans-serif">Other tricks:</span><br></div><div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">* If your initial intuitive drill down into the system bears no fruit, start caring about facts.</div><div style="font-family:arial,helvetica,sans-serif">* Measure the maximal latency over the equery call you've made for a 10-15 second period. Plot it.</div><div style="font-family:arial,helvetica,sans-serif">* We are interested in microstutters in the pacing. If they are present, it is likely there is some problem which then suddenly tips the system over. If not, then it is more likely that it is something we don't know.</div><div style="font-family:arial,helvetica,sans-serif">* The database might be fast, but there is still latency to the first byte, and there is the transfer time to the last byte. If a query is 50ms, say, then you are only going to run 20 of those per connection.</div><div style="font-family:arial,helvetica,sans-serif">* Pipeline the queries. A query which waits for an answer affects every sibling query as well.</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Down the line:</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">* Postgres can log slow queries. Turn that on.</div><div style="font-family:arial,helvetica,sans-serif">* Postgres can log whenever it holds a lock for more than a certain time window. Turn that on.</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Narrow down where the problem can occur by having systems provide facts to you. Don't go for "what is wrong?" Go for "What would I like to know?". This helps observability (In the Control Theory / Charity Majors sense).</div></div></div></div></blockquote><div><br></div></span><div>I did most of those. There are no slow queries, the database is literally sleeping. The issue is with the latency and the variance on the latency responses.</div><div><br></div><div>You nailed it at first: it's a matter of flow control. Simply put, my HTTP server is faster than the queries to the database (due to the extra-latency), even though prepared statements are used. This never occurs on other installations where databases are local, so I simply underestimated this aspect.</div><div><br></div><div>As per my previous statement, I'm going to add a flow restriction by which if there are no available database workers in the pool, I'll reject the HTTP call (I guess with a 503 or similar).</div><div><br></div><div>Thank you for your help,</div><div>r.</div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
</blockquote></div></div>