1

I have nginx web server running newest WordPress and DB server running MySQL 5.6 There is around 90-100ms latency(round-trip delay) between those 2 servers.

The problem is that It takes about 5000 ms to get response from my web-server if I access DB remotely.(The connection is encrypted by SSL)

In comparison it takes about 200 ms if I access MySQL locally(web-server & MySQL installed on one single machine).

1. Why is that ? Is it because WP has multiple MySQL queries per page and waits for each and every one to complete ? Therefore it adds up : 100+100+100+100..=5000ms ?

2. Can WP be modified to request from MySQL asynchronously, in order to reduce waiting time for request to be successful?

Thank you. :)

1 Answer 1

2

Yes

90-100ms round trip + time to prepare SQL statement + time to execute statement + time to send results back multiplied by the number of times you need to query the database.

Sure the connection may stay open but it's an inherently expensive thing to do.

Considering that some setups can respond in full in less than 100ms never mind the database connection, you should look into co-locating your database and your server, if not on to the same machine but somewhere very very close.

WordPress specific things that may help include:

  • Object caches
  • Database query caching
  • fewer SQL queries
  • Use of transients to store the results of expensive operations

You can see what SQL queries are made and slow queries using tools such as the query monitor plugin

3
  • Thank you, 1. "Considering that some setups can respond in full in less than 100ms never mind the database connection" How ? 2. Suppose you want to run WP on multiple geographical locations. What would you do ? Install DB server in each location and replicate between databases ? (Replication introduces new problem of data consistency) 3. Is there any other out-of-box web app similar to WP that can work with such latency ? (It does not have to be php+mysql based, even mongo+ruby)
    – no6
    Commented Mar 31, 2014 at 22:43
  • 1
    In this particular scenario, a fast server in the US would be faster worldwide than what you currently have, aside form exceptions such as China. Switching CMS isn't going to make the SQL query latency vanish if you want fast loading times. Continuing down this avenue leads to server related questions, and that would be off topic on this site. I suggest you find a good Server person
    – Tom J Nowell
    Commented Mar 31, 2014 at 22:59
  • In hindsight I should also have mentioned that if you have a database in the USA, and want to serve your site in New Zealand/Australia very quickly then that's not possible if you're connecting to a server in the USA, and that's not how big corporations do it, they replicate their database servers so that there are copies, and it's the copy/replicated/secondary database server that handles the request. Replication is a huge topic in and of itself, and there are lots of different strategies for doing it, e.g only handling writes in the USA DB server but reads are ok everywhere
    – Tom J Nowell
    Commented Jun 8, 2023 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.