Robby Williams Robby Williams - 1 year ago 75
MySQL Question

Does queries per second in MySql really matter?

For example, if you were to have a webpage that writes 10 times (

each query so relatively inexpensive) to a MySQL database every time you visited the page. Would it be the same thing as a page load that writes only one query that is
instead? What I'm basically asking is does queries per second really matter? Will it bottleneck my database faster?

If I had a pretty large database, is there any differences of writing 10000 inexpensive queries per second versus 1000 more expensive ones?

Answer Source

Besides the actual time spent executing a query, there is an overhead for your Rails application to establish a connection and close it.

Take your example of comparing one write of a certain amount of data versus 10 writes, each one-tenth the amount of data.

In the former case, only one database connection is needed, putting little stress on the connection pool. The write completes in 50ms, and during that time 9 other writes could also come in an execute. On the other hand, in the latter case, 10 connections from the pool must be used. And likely the amount of time needed for each of the 10 writes would be greater than 5ms, due to the overhead of establishing the connection.

Databases, like anything else, can benefit from economy of scale. Of course, there are instances when you simply need so many connections happening. But, all other factors being the same, if your business logic can be done with one large write rather than ten smaller ones, you might want to go for the single write.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download