[英]PHP script much slower on server than on WAMP localhost
So as I've stated above: I have a quite big, but quite easy script, which gets a single json file from a website, decodes it, then saves the data in a PostgreSQL database. 因此,如上所述,我有一个很大但很简单的脚本,该脚本从网站获取一个json文件,对其进行解码,然后将数据保存在PostgreSQL数据库中。 It takes about 4 to 5 minutes to completely finish (about 300 000 records) on my computer (i3M CPU, laptop) but takes a about 10-15 times longer to do the same thing on the server which I've just rented.
在我的计算机(i3M CPU,笔记本电脑)上完全完成(大约300 000条记录)大约需要4到5分钟,但是在我刚刚租用的服务器上完成同一操作大约需要10到15倍的时间。
The dedicated server has an intel Xeon quad (3Ghz) CPU, and on an overall level much better specifications with much better internet access, so I'm pretty sure it has nothing to do with that. 专用服务器具有英特尔至强四核(3Ghz)CPU,并且总体上具有更好的规格和更好的Internet访问,因此,我敢肯定与它无关。 It runs the latest Debian, Apache/2.4.10, PHP Version 5.6.22-0, PostgreSQL 9.5.
它运行最新的Debian,Apache / 2.4.10,PHP版本5.6.22-0,PostgreSQL 9.5。
I've tried to copy the settings and modules from the WAMP settings, figured it my help. 我试图从WAMP设置中复制设置和模块,以得到我的帮助。 Unfortunately, it didn't.
不幸的是,事实并非如此。 Not sure what information might help in solving this problem, but I'm more than happy to answer to any of the questions.
不知道什么信息可以帮助解决这个问题,但是我很乐意回答任何问题。
I am almost positive it has something to do with some option which I must have skipped, so any help would be much appreciated. 我几乎可以肯定,它与某些必须跳过的选项有关,因此,我们将不胜感激。
PS: WAMP uses: 2.4.17 Apache, 5.6.16 PHP, 9.5 PostgreSQL. PS:WAMP使用:2.4.17 Apache,5.6.16 PHP,9.5 PostgreSQL。
Performance-Issues can be caused by much things. 性能问题可能是由很多原因引起的。
You should write some Scripts to "identify" the bottleneck: 您应该编写一些脚本来“识别”瓶颈:
if you didn't encounter a (unexpected) difference by now, you have eliminated hardware-issues. 如果您现在没有遇到(意外的)差异,那么您已经消除了硬件问题。 - Repeat the task for heavy database loads to figure out if the database might be missconfigured.
-对繁重的数据库负载重复执行此任务,以弄清数据库是否配置错误。 Sometimes it is just a simple "Boolean" flag, that might have heavy performance-impacts.
有时,它只是一个简单的“布尔”标志,可能会严重影响性能。
To expand on dognose's answer, I find that optimizing your DB access can make a big difference in performance. 为了进一步了解Dognose的答案,我发现优化数据库访问可以在性能上产生很大的不同。
It might be interesting to see what happens to the run time if you comment out the DB queries. 注释掉数据库查询后,看看运行时会发生什么可能会很有趣。 This will tell you how much of the run time is spent on the DB.
这将告诉您在数据库上花费了多少运行时间。
If the DB is taking significant time, try batching your requests. 如果数据库花费大量时间,请尝试分批处理您的请求。 Instead of sending a single insert at a time to the DB, try holding them in a variable and sending over 50 to 100 inserts (or more) in a batch.
尝试一次将它们保存在变量中,然后批量发送50至100个(或更多)插入,而不是一次将单个插入发送到DB。 Depending on how you setup your DB connection, there could be significant overhead for each request.
根据您设置数据库连接的方式,每个请求可能会有大量开销。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.