Improving network latency - online gaming site
I operate an online browser game that is very AJAX/database dependent, and the problem I am encountering is excessively high latency during peak hours.
I've created a simple AJAX ping that checks the server in a per-second loop, and the execution/response times of the 5 most recent pings are averaged into a "Connection Speed" that is displayed on the screen.
Most times, this latency records anywhere from 100-350ms, depending on internet speed, the client's other running webpages, and various other t开发者_如何学编程hings. However, during peak hours on my server, namely 10PM-11PM EST, this latency becomes so bad that my AJAX functions stop working. The latency during these times can be around 2000ms, with some people seeing it as high as 6800ms.
My question is.. what would be the most likely cause of this? Is it a hardware issue on my server? Is it just unfeasible to create a browser game purely powered by AJAX? During these times, I often encounter issues on the server itself, with my control panel returning many "Cannot allocate memory for selected task" errors, yet when I run free
through SSH, not even 10% of the RAM is being used.
You are experiencing contention somewhere in your web app or database. This can be in so many places and therefore has so many possible resolutions that it is impossible to list them. Some of the things you can think about:
- No threads available to handle incoming requests because they are making synchronous calls to the database which will lock the thread until the database returns thus increasing latency
- Contention at the databse level. Are you using partitioning for your data to support true concurrency?
- Are you serving static content through your web app which could be retrieved as a directly addressable resource?
- Are you load balancing your web app?
- Are you using caching on the web app?
It's a bit like "how long is a piece of string?"
Hope this helps some.
精彩评论