JSON-RPC和性能问题
在我开发的新项目中,我选择了 json-rpc 方式,带有客户端模板和大量 JavaScript 内容。问题是 - apache 与 php (实际上 php 解析 json 查询)非常慢。我每页大约有 20 个查询,并且需要很长时间才能加载所有内容。
我的梦想是让它成为可能,将 javascript 直接与 tcp/ip 协议连接到后端(用 php 编写),但我知道这是不可能的(没有 flash)。
您能给我任何建议吗?如何提高该解决方案的速度?也许用 nginx 替换 apache 甚至编写专用的 httpd 可能会有所帮助?
With the new project I develop, i choosed the json-rpc way, with client side templates and alot of javascript stuff. The problem is - apache with php (actually php parses json query) is pretty slow. I have approximately 20 queries per page and it takes long time to have everything loaded.
My dream is to get it possible, to connect javascript directly with tcp/ip protocol to backend (written in php) but I know it's not possible (without flash).
Can you please give me any suggestion, how to improve speed of this solution? Maybe replacing apache with nginx or even write dedicated httpd may help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您每页进行 20 个查询,我怀疑更好的数据交换格式会有很大帮助。除非您正在处理大量 JSON,否则我的猜测是,获得性能提升的最简单方法是减少查询数量(可能通过对查询进行批处理)。
其他一些可能有帮助的事情:使用 MinSpareServers< 确保 Apache 有足够的备用进程/a>,确保所有 JSON 都经过 gzip 压缩(例如,使用
mod_deflate
),分析您的代码以验证 JSON 解码实际上速度较慢,并且时间不会进入例如缓慢的数据库查询。If you're making 20 queries per page, I doubt a better data interchange format will help a whole lot. Unless you're dealing with a huge amount of JSON, my guess is that the simplest way to get a performance boost will be to reduce the number of queries (possibly by batching them).
Some other things that might help: make sure Apache has enough spare processes using MinSpareServers, make sure all the JSON is being gzip'd (eg, using
mod_deflate
), profile your code to verify that decoding the JSON is actually what's slow, and the time isn't going into, eg, a slow DB query.你的情况并不简单,所以解决方案也不是微不足道的。
phpDaemon 是一个高性能的真正快速的 CGI 解决方案。
使用 phpDaemon,您的代码将无需初始化开销即可运行,因此一旦时间初始化,脚本就可以以极快的速度处理大量请求。
Your case is not trivial, so solution is not trivial too.
phpDaemon is a high performance true-Fast-CGI solution.
With phpDaemon, your code will run without overhead for initialization, so once time initialized, script can process a lot of requests with furious speed.