php-cgi frozen with sbwait when SMP enable

Added by kenchen almost 2 years ago

I have 4 web servers with lighttpd to serve one web site by DNS load sharing. On the 2 SMP-enable web servers, there will be many php-cgi frozen in 'sbwait' state every day. It means the php-cgi stay in 'sbwait' state, and never be back to 'accept' or other state. If I restart them, there will be frozen php-cgi appear some hours later.

There is no problem on the other single CPU web servers which running same php scripts and same configuration and version of PHP.

Generally, the PID of php-cgi should be in a short range. But some php-cgi are frozen, they stay in the system, do nothing!

web4# ps alx | grep php-cgi | grep -v grep | grep sbwait
65534 61399 61384 0 4 -15 182328 71112 sbwait I< ?? 1:09.60 /usr/local/bin/php-cgi
65534 61409 61384 0 4 -15 182328 72812 sbwait I< ?? 1:39.40 /usr/local/bin/php-cgi
65534 61411 61384 0 4 -15 183352 74536 sbwait I< ?? 1:49.08 /usr/local/bin/php-cgi
65534 61412 61384 0 4 -15 183352 74508 sbwait I< ?? 1:33.31 /usr/local/bin/php-cgi
65534 61414 61384 0 4 -15 182328 62860 sbwait I< ?? 0:28.81 /usr/local/bin/php-cgi
65534 61418 61384 0 4 -15 182328 71448 sbwait I< ?? 1:17.56 /usr/local/bin/php-cgi
65534 61426 61384 0 4 -15 183352 60456 sbwait I< ?? 0:22.16 /usr/local/bin/php-cgi
65534 71529 61384 0 4 -15 182328 74144 sbwait I< ?? 0:36.87 /usr/local/bin/php-cgi
65534 71555 61384 0 4 -15 182328 72820 sbwait I< ?? 0:19.19 /usr/local/bin/php-cgi
65534 71556 61384 0 4 -15 182328 74452 sbwait I< ?? 0:38.27 /usr/local/bin/php-cgi
65534 71590 61384 0 4 -15 182328 76828 sbwait I< ?? 0:57.42 /usr/local/bin/php-cgi
65534 71594 61384 0 4 -15 182328 75576 sbwait I< ?? 0:46.50 /usr/local/bin/php-cgi
65534 71595 61384 0 4 -15 182328 84048 sbwait I< ?? 1:52.15 /usr/local/bin/php-cgi
65534 77401 61384 1 4 -15 182328 98596 sbwait I< ?? 1:06.56 /usr/local/bin/php-cgi
65534 78159 61384 3 4 -15 182328 101428 sbwait I< ?? 1:18.58 /usr/local/bin/php-cgi

web4# /usr/local/bin/php-cgi -v
PHP 5.2.6 (cgi-fcgi) (built: Nov 2 2008 11:16:30)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with XCache v1.2.2, Copyright (c) 2005-2007, by mOo
web4# /usr/local/lighttpd/sbin/lighttpd -v
lighttpd-1.4.19 - a light and fast webserver
Build-Date: Sep 1 2008 16:58:51
web4# uname -a
FreeBSD web4.xxxx.com 7.0-RELEASE-p5 FreeBSD 7.0-RELEASE-p5 #11: Mon Nov 3 01:10:36 CST 2008 :/usr/obj/usr/src/sys/WEB4 i386

in lighttpd.conf

  1. fastcgi module
    fastcgi.server = (
    ".php" =>
    ((
    "socket" => "/tmp/fastcgi.sock",
    "bin-path" => "/usr/local/bin/php-cgi",
    "min-procs" => 1,
    "max-procs" => 1,
    "idle-timeout" => 20,
    "bin-environment" => (
    "PHP_FCGI_CHILDREN" => "48",
    "PHP_FCGI_MAX_REQUESTS" => "5000"
    )
    ))
    )

Why and any solution? Or it's a PHP problem?

Thanks!


Replies (13)

RE: php-cgi frozen with sbwait when SMP enable - Added by icy almost 2 years ago

sbwait state means there is some socket event that php is waiting for but never happens. Can you check what they are actually waiting for?
Attach gdb to a php process in sbwait state and then type in "bt" to get a backtrace. Or attach with strace/ktrace and see if that turns out anything usefull.

Without knowing what php is waiting for, it's impossible to tell what the problem is.

RE: php-cgi frozen with sbwait when SMP enable - Added by c0nsumer almost 2 years ago

I can reliably reproduce this. Here's the config of the system:

FreeBSD 7.0-RELEASE amd64 using an SMP kernel with SCHED_ULE. PHP 5.2.6 and lighttpd-1.4.19_3 from ports running as a FastCGI. I can reliably reproduce this by running Gallery2 (2.2 or 2.3) and doing an upload with Gallery Remote. After a few images are uploaded the applet hangs with "Upload complete: server processing" and one of the copies of php-cgi are hang as sbwait.

Here's what I was able to get so far. Since I can reproduce this at will I'll gladly reproduce it as needed to gather more info. Just let me know what you need.

As seen in top:

81073 c0nsumer        1   4    0   116M 20988K sbwait 3   0:01  0.00% php-cgi

Some basic info from gdb:

c0nsumer@banstyle:/> sudo gdb /usr/local/bin/php-cgi 81073

(gdb) bt
#0  0x00000008010a476a in read () from /lib/libc.so.7
#1  0x000000000057d5fc in fcgi_read ()
#2  0x000000000057e306 in sapi_cgi_read_post ()
#3  0x00000000004c84a4 in fill_buffer ()
#4  0x00000000004c88b5 in multipart_buffer_read ()
#5  0x00000000004c9c08 in rfc1867_post_handler ()
#6  0x00000000004c6ee5 in sapi_handle_post ()
#7  0x00000000004cc30c in php_default_treat_data ()
#8  0x00000000004cc7eb in php_hash_environment ()
#9  0x00000000004bff47 in php_request_startup ()
#10 0x000000000057f8c6 in main ()

(gdb) f 0
#0  0x00000008010a476a in read () from /lib/libc.so.7
(gdb) info frame
Stack level 0, frame at 0x7fffffff9c50:
 rip = 0x8010a476a in read; saved rip 0x57d5fc
 called by frame at 0x7fffffff9db0
 Arglist at 0x7fffffff9c40, args: 
 Locals at 0x7fffffff9c40, Previous frame's sp is 0x7fffffff9c50
 Saved registers:
  rip at 0x7fffffff9c48

RE: php-cgi frozen with sbwait when SMP enable - Added by c0nsumer almost 2 years ago

I noticed that 1.4.20 was in ports, so I upgraded to that to give it a try. That didn't resolve the problem and I was able to reproduce it after uploading just two ~5MB images.

RE: php-cgi frozen with sbwait when SMP enable - Added by darix almost 2 years ago

ok. we just had an user with a similar problem and for him
server.network-backend = "writev"
server.event-handler = "freebsd-kqueue"

fixed the issue. can you please test that and report back?

RE: php-cgi frozen with sbwait when SMP enable - Added by c0nsumer almost 2 years ago

server.network-backend = "writev" seems to have done it. Doing the same test as before, 36 photos have uploaded without a problem. A friend with the same issue on a different server (similar config) tried this as well, and it seems to have sorted things out for him as well.

server.event-handler = "freebsd-kqueue" was already set, so that likely didn't have an impact. From what I can tell, the default server.network-backend setting is "write". Is that correct?

RE: php-cgi frozen with sbwait when SMP enable - Added by darix almost 2 years ago

yes the default is write and seems horribly broken on fbsd 7.
i got reports on 6.3 it was working properly with
server.network-backend = "write"
server.event-handler = "freebsd-kqueue"

so what ever happened it broke something.

RE: php-cgi frozen with sbwait when SMP enable - Added by c0nsumer almost 2 years ago

I actually had it working great on 6.3 myself with write (because it was the default and not set), and with freebsd-kqueue manually specified. So, add me to that list as well.

Thanks for your help on this, I'm glad to know there is a solution. Hopefully a more permanent fix can be put in place eventually, wherever it is needed.

RE: php-cgi frozen with sbwait when SMP enable - Added by c0nsumer almost 2 years ago

By the way, I'd read that server.network-backend = "freebsd-sendfile" breaks the OS itself pretty horribly. Any idea if this is still the case? I'd try it, but the server I'm currently working with is in production and I don't have a handy spare.

RE: php-cgi frozen with sbwait when SMP enable - Added by stbuehler almost 2 years ago

IIRC there where some problems if you tried freebsd-sendfile with unix sockets, it guess it will work for tcp connections. (the network-backend is used for the connections to fastcgi/... too).

The main problem is that there is no "fallback" if the OS tells us that it doesn't support sendfile on a specific socket or file.

RE: php-cgi frozen with sbwait when SMP enable - Added by kenchen almost 2 years ago

Thanks!

I will try

#server.network-backend = "freebsd-sendfile"
server.network-backend = "writev"

RE: php-cgi frozen with sbwait when SMP enable - Added by kenchen almost 2 years ago

3 days later, no more frozen php-cgi.

Thanks a lot.

php-cgi no longer broken with freebsd-sendfile, on SMP-machines running 7.1-RELEASE (Was: php-cgi frozen with sbwait when SMP enable) - Added by mr_bond over 1 year ago

freebsd-sendfile worked fine for me in 6.3-RELEASE, but when I upgraded to 7.0-RELEASE I noticed same problems as described, easily reproducable, switching to "writev" also solved the problem..

However.. I was going to get a stack-trace of the problem for darix, but after upgrading the server in question to 7.1-RELEASE (using freebsd-update (this also patches the KERNEL to use the new SCHED_ULE scheduler)), I could no longer reproduce the problem with php-uploads/fcgi via socket.

I've tried to reproduce it all day, with everything from ubuntu 700MB ISO-file, to SLES10.1 4.3GB DVD ISO-file - without successfully leaving process hanging.

I suggest others having this issue tries to upgrade to 7.1-RELEASE if possible, and report back if there is any issues with it.

PS: this is also an SMP system

Cheers!

RE: php-cgi frozen with sbwait when SMP enable - Added by kenchen over 1 year ago

Really good news!

I will try before the Chinese New Year.

(1-13/13)