doushichun9409
2014-01-16 07:44
浏览 11
已采纳

PHP Web服务优化和测试方法

I'm working on a web service in PHP which accesses an MSSQL database and have a few questions about handling large amounts of requests.

  1. I don't actually know what constitutes 'high traffic' and I don't know if my service will ever experience 'high traffic' but would optimisations in this area be largely attributed to the server processing speed and database access speed?

  2. Currently when a request is sent to the server I do the following:

    • Open database connection
    • Process Request
    • Return data

    Is there anyway I can 'cache' this database connection across multiple requests? As long as each request was processed simultaneously the database will remain valid.

  3. Can I store user session id and limit the amount of requests per hour from a particular session?

  4. How can I create 'dummy' clients to send requests to the web server? I guess I could just spam send requests in a for loop or something? Better methods?

Thanks for any advice

图片转代码服务由CSDN问答提供 功能建议

我正在使用PHP中的Web服务来访问MSSQL数据库并且有一些关于处理大量数据的问题 请求。

  1. 我实际上并不知道什么是“高流量”,我不知道我的服务是否会遇到“高流量” 但是这方面的优化主要归功于服务器处理速度和数据库访问速度吗?

  2. 目前,当请求发送到服务器时,我会执行以下操作: / p>

    • 打开数据库连接
    • 处理请求
    • 返回数据

      无论如何,我可以跨多个请求“缓存”此数据库连接吗? 只要同时处理每个请求,数据库就会保持有效。

    • 我可以存储用户会话ID并限制特定会话中每小时的请求数量吗?

    • 如何创建'虚拟'客户端以向Web服务器发送请求? 我想我可以只是垃圾邮件发送请求在for循环或什么? 更好的方法?

      感谢您的任何建议

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drf97973 2014-01-16 08:16
    已采纳
    1. You never know when high traffic occurs. High traffic might result from your search engine ranking, a blog writing a post of your web service or from any other unforseen random event. You better prepare yourself to scale up. By scaling up, i don't primarily mean adding more processing power, but firstly optimizing your code. Common performance problems are:

      • unoptimized SQL queries (do you really need all the data you actually fetch?)
      • too many SQL queries (try to never execute queries in a loop)
      • unoptimized databases (check your indexing)
      • transaction safety (are your transactions fast? keep in mind that all incoming requests need to be synchronized when calling database transactions. If you have many requests, this can easily lead to a slow service.)
      • unnecessary database calls (if your access is read only, try to cache the information)
      • unnecessary data in your frontend (does the user really need all the data you provide? does your service provide more data than your frontend uses?)
    2. Of course you can cache. You should indeed cache for read-only data that does not change upon every request. There is a useful blogpost on PHP caching techniques. You might also want to consider the caching package of the framework of your choice or use a standalone php caching library.

    3. You can limit the service usage, but i would not recommend to do this by session id, ip address, etc. It is very easy to renew these and then your protection fails. If you have authenticated users, then you can limit the requests on a per-account-basis like Google does (using an API key for all their publicly available services per user)

    4. To do HTTP load and performance testing you might want to consider a tool like Siege, which exactly does what you expect.

    I hope to have answered all your questions.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题