PHP 需要额外 1 秒才能从 Sphinx 检索每个结果集(!!)

发布于 2024-11-05 10:48:12 字数 1937 浏览 6 评论 0原文

我遇到了一个奇怪的问题......昨晚当我编写该死的东西时,一切都工作正常,但我在本地开发服务器上重新安装了 WAMP,现在我遇到了问题。

我正在尝试通过 PHP api 从 Sphinx 检索结果。我只是执行最基本的查询作为测试...

    $searchtest = Sphinx::factory();
    $results = $searchtest->Query('');

并且 $results 包含预期的 sphinx 结果

...
[total] => 1000
[total_found] => 30312
[time] => 0.004

但是,当我分析这一小段代码时,它告诉我 PHP 需要额外的一秒钟来处理查询!

test (1) - 1.066703 s

昨天,我的生产代码运行了多次 Sphinx 搜索,问题变得更糟...一切都运行良好,每次搜索花费了 0.004 秒(或同样少量的时间),但今天,页面需要几秒钟来运行所有搜索查询! (这是在一个独立的开发服务器上,因此没有流量问题)

results (1) - 1.046128 s
sidebar_data (1) - 10.388812 s
featured (1) - 1.034211 s

对 Sphinx 守护程序的每个单独查询都需要额外的一秒钟才能返回! (sidebar_data 访问搜索服务器 10 次)

这是怎么回事?我浪费了很多时间试图弄清楚它,但我被难住了。我什至从头开始重新安装了 Sphinx。由于 sphinx 本身正在报告 [time] => 0.004 快速访问时间,问题与 PHP 有关吗?

我应该做什么来诊断问题?

编辑:我查看了 searchd --console 的输出,果然,它确认搜索查询运行得相当快,但是如果您查看时间,它们正在执行大约。每秒一个... PHP 不知何故造成了一些延迟(??)

[Sun May  8 09:57:29.923 2011] 0.012 sec [all/1/ext 15039 (0,25)] [main]
[Sun May  8 09:57:30.996 2011] 0.020 sec [all/1/rel 30 (0,20) @city] [main]
[Sun May  8 09:57:32.034 2011] 0.016 sec [all/1/rel 50 (0,20) @make] [main]
[Sun May  8 09:57:33.061 2011] 0.015 sec [all/1/rel 15 (0,20) @style] [main]
[Sun May  8 09:57:34.099 2011] 0.017 sec [all/1/rel 25 (0,20) @colour] [main]
[Sun May  8 09:57:35.122 2011] 0.009 sec [all/1/rel 1 (0,20) @field] [main]
[Sun May  8 09:57:36.145 2011] 0.011 sec [all/2/rel 1 (0,20) @field] [main]
[Sun May  8 09:57:37.174 2011] 0.010 sec [all/2/rel 1 (0,20) @field] [main]
[Sun May  8 09:57:38.187 2011] 0.003 sec [all/2/rel 431 (0,20)] [main]
[Sun May  8 09:57:39.240 2011] 0.005 sec [all/2/rel 12627 (0,20)] [main]
[Sun May  8 09:57:40.292 2011] 0.005 sec [all/2/rel 13021 (0,20)] [main]
[Sun May  8 09:57:41.343 2011] 0.001 sec [all/3/rel 200 (0,20)] [main]

I'm running into a strange issue.... This all worked fine last night when I coded the damn thing, but I reinstalled WAMP on my local dev server and now I'm running into problems.

I'm attempting to retrieve results from Sphinx through the PHP api. I'm just executing the most basic of queries as a test...

    $searchtest = Sphinx::factory();
    $results = $searchtest->Query('');

And $results contains the sphinx results as expected

...
[total] => 1000
[total_found] => 30312
[time] => 0.004

However, when I profile this small piece of code, it's telling me that PHP is taking an extra second to process the query!

test (1) - 1.066703 s

The problem gets worse on my production code which runs several Sphinx searches, yesterday... everything was running fine and each search took 0.004sec (or an equally small amount of time) but today, the page takes several seconds to run all the search queries! (this is on an isolated dev server, so no traffic issues)

results (1) - 1.046128 s
sidebar_data (1) - 10.388812 s
featured (1) - 1.034211 s

Each separate query to the Sphinx daemon takes an extra second to come back! (sidebar_data hits the search server 10 times)

What is going on here? I've wasted a bunch of time trying to figure it out and I'm stumped. I even reinstalled Sphinx from scratch. Since sphinx itself is reporting [time] => 0.004 fast access times, is the problem something to do with PHP?

What should I do to diagnose the problem?

Edit: I looked at the output from searchd --console, sure enough, it confirms that the search queries are quite quick to run, but if you look at the time, they are being executed approx. one per second... PHP is causing some delay somehow(??)

[Sun May  8 09:57:29.923 2011] 0.012 sec [all/1/ext 15039 (0,25)] [main]
[Sun May  8 09:57:30.996 2011] 0.020 sec [all/1/rel 30 (0,20) @city] [main]
[Sun May  8 09:57:32.034 2011] 0.016 sec [all/1/rel 50 (0,20) @make] [main]
[Sun May  8 09:57:33.061 2011] 0.015 sec [all/1/rel 15 (0,20) @style] [main]
[Sun May  8 09:57:34.099 2011] 0.017 sec [all/1/rel 25 (0,20) @colour] [main]
[Sun May  8 09:57:35.122 2011] 0.009 sec [all/1/rel 1 (0,20) @field] [main]
[Sun May  8 09:57:36.145 2011] 0.011 sec [all/2/rel 1 (0,20) @field] [main]
[Sun May  8 09:57:37.174 2011] 0.010 sec [all/2/rel 1 (0,20) @field] [main]
[Sun May  8 09:57:38.187 2011] 0.003 sec [all/2/rel 431 (0,20)] [main]
[Sun May  8 09:57:39.240 2011] 0.005 sec [all/2/rel 12627 (0,20)] [main]
[Sun May  8 09:57:40.292 2011] 0.005 sec [all/2/rel 13021 (0,20)] [main]
[Sun May  8 09:57:41.343 2011] 0.001 sec [all/3/rel 200 (0,20)] [main]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2024-11-12 10:48:12

乍一看,我猜测可能涉及某种 DNS 解析问题,但似乎您在与 PHP 相同的主机上运行 searchd

而不是四处寻找导致此问题的原因建议分析机器上运行的 PHP 代码。我将安装 xdebug,启用分析,然后分析 webcachegrind 中的输出。它应该能够指出哪些函数运行缓慢,并为您提供更好的线索来了解问题所在。

At a first look I'd have guessed some kind of DNS resolution problem could be involved but it seems like your running searchd on the same host as PHP

Rather than poke around trying to guess what is causing this I would recommend profiling the PHP code running on the machine. I would install xdebug, enable profiling and then analyse the output in webcachegrind. It should be able to point you to which functions are slow to run and give you a better clue as to what's wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文