Robby Williams
Robby Williams

Reputation: 115

Does queries per second in MySql really matter?

For example, if you were to have a webpage that writes 10 times (5ms 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 50ms 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?

Upvotes: 0

Views: 1108

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521053

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 and execute. On the other hand, in the latter case, 10 connections from the pool must be used for the same data alone. 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.

Upvotes: 2

Related Questions