开发者

PHP taking extra 1 second to retrieve each result set from Sphinx(!!)

开发者 https://www.devze.com 2023-03-03 23:11 出处:网络
I\'m running into a strange issu开发者_如何学Pythone.... 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 running into a strange issu开发者_如何学Pythone.... 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]


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.

0

精彩评论

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