开发者

GET Requests vs JavaScript

Alright, I have a JavaScript doing HTTP Requests to a PHP file onto the same directory. Then it's returning it's output.

Let's say there are 开发者_运维技巧over 50+ people doing this request simultaneously ... will it slow down anything? Yes, this may seem like a dumb question - but sorry. :|

Thank you.


It really depends on your backend code.

I have a php file for a scrabble type game, which simply checks if the word is valid. This does a database lookup, and responds with a true or false. It sounds like your request is doing something very similar. The way you are doing it is one of the most efficient ways, because you are only checking the results, rather than doing a full page reload.

The result is less than 20ms usually, and under load does not particularly increase that much. But my code is doing very little.

In principle though, what you are doing is fine.


Potentially yes. There are some basic questions to answer:

  • How long does riddle.php take to execute?
  • How many simultaneous requests can your server handle?

Note that the first answer may vary if riddle.php accesses any shared resources (files, database tables) that may require locking for updates.


Factors as to why this can't be answered


  1. Hardware Limitations - what kind of server? how much memory? how much free resources (eg any other demanding applications running at the time)
  2. Network Limitations - what kind of connection? how saturated is the network?
  3. Application Limitations - what is riddle.php doing? how is the db query constructed? what does the JavaScript do with the returned result?
  4. Database Limitations - how many concurrent connections are allowed? how many can be supported? how is the db optimized?

Ways to approach


  1. Cache the php as much as you can
  2. Cache previous queries as much as you can
  3. Create a database connection pool (a large percentage of the time is spent in opening new connections)


Dealing with multiple requests at once will need server resources. It may or may not slow things down appreciably depending on how much load the server and network connection can handle.


Depends on several factors. Are you caching your pages? this would speed up page rendering. how fast is the actual riddle.php script, is the DB interaction that could get bogged down? what is the capacity/memory of the server you files are hosted on, what is the connection speed to that server? how much data are you rendering back? all these things figure into your answer. The best thing to do is actually write something to simulate your expected load and check your results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜