php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46723 FastCGI is incredibly slow due to TCP ack delay
Submitted: 2008-11-30 17:42 UTC Modified: 2010-09-13 13:42 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jost_boekemeier at users dot sf dot net Assigned: dmitry (profile)
Status: Closed Package: CGI/CLI related
PHP Version: 5CVS, 6CVS (2008-12-08) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jost_boekemeier at users dot sf dot net
New email:
PHP Version: OS:

 

 [2008-11-30 17:42 UTC] jost_boekemeier at users dot sf dot net
Description:
------------
The PHP side of a socket-based FastCGI communication is unbuffered since PHP 5.1.4 (maybe earlier). 

write/write/read cycles have a huge performance impact, on the latest Linux kernel the FastCGI SAPI is actually slower than executing a CGI for each request!

The actual problem is caused by the two unbuffered write() operations, which run into a delayed ack and therefore cause a latency of 40000us on FC10 and 500ms(!) on FreeBSD.

As an immediate fix I suggest to switch on NDELAY for the PHP FastCGI socket communication. I can provide a patch if you want me to.


Regards,
Jost Bökemeier



Reproduce code:
---------------
-

Expected result:
----------------
-

Actual result:
--------------
-

Patches

php-fcgi-ndelay.patch (last revision 2010-03-20 17:36 UTC by jost_boekemeier at users dot sf dot net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-21 19:27 UTC] jani@php.net
Patches are always welcome, you don't need to wait for a request..:)
 [2009-01-29 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-03-20 18:41 UTC] jost_boekemeier at users dot sf dot net
Please excuse the delay. I didn't noticed that you were asking for a patch.

After applying the patch fastcgi renders 900 pages in 1m8.095s, compared to 1m40.428s before.


[notice for me]

$ time for i in `seq 900`; do wget -O/dev/null -o/dev/null http://localhost:8080/JavaBridge/sessionSharing.php; done

real	1m40.428s
user	0m1.587s
sys	0m3.108s
$ time for i in `seq 900`; do wget -O/dev/null -o/dev/null http://localhost:8080/JavaBridgeO/sessionSharing.php; done

real	1m8.095s
user	0m1.212s
sys	0m2.485s
 [2010-03-23 05:56 UTC] aharvey@php.net
-Status: No Feedback +Status: Open
 [2010-08-22 20:58 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2010-08-25 14:55 UTC] dmitry@php.net
-Status: Assigned +Status: Feedback
 [2010-08-25 14:55 UTC] dmitry@php.net
I've tested your patch on Linux 2.6.27 and it doesn't make any visible difference.

May be you used different URLs? (In your last post JavaBridge != JavaBridgeO)

Also it would be better to use special programs to benchmark (e.g. ab or http_load)
 [2010-08-26 17:03 UTC] jost_boekemeier at users dot sf dot net
-Status: Feedback +Status: Assigned
 [2010-08-26 17:03 UTC] jost_boekemeier at users dot sf dot net
Test machine was FC10 with a fedora-patched kernel 2.6.25.

It is possible to eliminate the ack delay on kernel-level (e.g. make NDELAY default for local tcp connections). But in fc9, fc10 and fc11 the problem was, and in FreeBSD the problem is, very visible.

Bridge0 was identical to Bridge except for the NDELAY patch.


An alternative approach would be to add a write cache which grows dynamically, and which is flushed each time read() is called. But I think this is too much overhead.
 [2010-08-26 17:25 UTC] dmitry@php.net
-Status: Assigned +Status: Feedback
 [2010-08-26 17:25 UTC] dmitry@php.net
I don't know what is the "ack delay". As I know TCP_NODELAY just disables the Nagle algorithm and this makes packets to be always sent ASAP. As result it may produce more packets. Probably it may affect FastCGI only in some specific scenarios.

Could you please provide a php script, without external dependencies (databases, Java, etc) which demonstrates the problem. (you can send it by email if it's too big)

Also which web server and fastcgi manager do you use?
 [2010-08-28 18:37 UTC] jost_boekemeier at users dot sf dot net
-Status: Feedback +Status: Assigned
 [2010-08-28 18:37 UTC] jost_boekemeier at users dot sf dot net
Test script below:
------------- ack_delay.php ---
<?php
$data=array(0x1,0x1,0x0,0x1,0x0,0x8,0x0,0x0,0x0,0x1,0x1,0x0,0x0,0x0,0x0,0x0,0x1,0x4,0x0,0x1,0xe,0x65,0x0,0x0,0x4,0x5,0x54,0x45,0x52,0x4d,0x78,0x74,0x65,0x72,0x6d,0x14,0xe,0x48,0x54,0x54,0x50,0x5f,0x41,0x43,0x43,0x45,0x50,0x54,0x5f,0x4c,0x41,0x4e,0x47,0x55,0x41,0x47,0x45,0x65,0x6e,0x2d,0x75,0x73,0x2c,0x65,0x6e,0x3b,0x71,0x3d,0x30,0x2e,0x35,0x10,0x13,0x53,0x45,0x52,0x56,0x45,0x52,0x5f,0x53,0x49,0x47,0x4e,0x41,0x54,0x55,0x52,0x45,0x41,0x70,0x61,0x63,0x68,0x65,0x20,0x54,0x6f,0x6d,0x63,0x61,0x74,0x2f,0x37,0x2e,0x30,0x2e,0x32,0x12,0x9,0x48,0x54,0x54,0x50,0x5f,0x43,0x41,0x43,0x48,0x45,0x5f,0x43,0x4f,0x4e,0x54,0x52,0x4f,0x4c,0x6d,0x61,0x78,0x2d,0x61,0x67,0x65,0x3d,0x30,0xf,0x3d,0x53,0x45,0x53,0x53,0x49,0x4f,0x4e,0x5f,0x4d,0x41,0x4e,0x41,0x47,0x45,0x52,0x6c,0x6f,0x63,0x61,0x6c,0x2f,0x75,0x6e,0x69,0x78,0x3a,0x40,0x2f,0x74,0x6d,0x70,0x2f,0x2e,0x49,0x43,0x45,0x2d,0x75,0x6e,0x69,0x78,0x2f,0x32,0x31,0x32,0x32,0x2c,0x75,0x6e,0x69,0x78,0x2f,0x75,0x6e,0x69,0x78,0x3a,0x2f,0x74,0x6d,0x70,0x2f,0x2e,0x49,0x43,0x45,0x2d,0x75,0x6e,0x69,0x78,0x2f,0x32,0x31,0x32,0x32,0x18,0x12,0x47,0x4e,0x4f,0x4d,0x45,0x5f,0x44,0x45,0x53,0x4b,0x54,0x4f,0x50,0x5f,0x53,0x45,0x53,0x53,0x49,0x4f,0x4e,0x5f,0x49,0x44,0x74,0x68,0x69,0x73,0x2d,0x69,0x73,0x2d,0x64,0x65,0x70,0x72,0x65,0x63,0x61,0x74,0x65,0x64,0xb,0x5,0x52,0x45,0x4d,0x4f,0x54,0x45,0x5f,0x50,0x4f,0x52,0x54,0x35,0x38,0x39,0x32,0x31,0x14,0xc,0x48,0x54,0x54,0x50,0x5f,0x41,0x43,0x43,0x45,0x50,0x54,0x5f,0x45,0x4e,0x43,0x4f,0x44,0x49,0x4e,0x47,0x67,0x7a,0x69,0x70,0x2c,0x64,0x65,0x66,0x6c,0x61,0x74,0x65,0x4,0x16,0x4d,0x41,0x49,0x4c,0x2f,0x76,0x61,0x72,0x2f,0x73,0x70,0x6f,0x6f,0x6c,0x2f,0x6d,0x61,0x69,0x6c,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0xa,0x5,0x47,0x44,0x4d,0x53,0x45,0x53,0x53,0x49,0x4f,0x4e,0x67,0x6e,0x6f,0x6d,0x65,0x12,0x3d,0x58,0x44,0x47,0x5f,0x53,0x45,0x53,0x53,0x49,0x4f,0x4e,0x5f,0x43,0x4f,0x4f,0x4b,0x49,0x45,0x64,0x33,0x33,0x66,0x38,0x66,0x62,0x61,0x38,0x62,0x33,0x65,0x37,0x64,0x33,0x64,0x39,0x64,0x38,0x35,0x34,0x37,0x66,0x36,0x34,0x39,0x33,0x31,0x33,0x65,0x34,0x36,0x2d,0x31,0x32,0x38,0x33,0x35,0x34,0x32,0x32,0x34,0x35,0x2e,0x32,0x30,0x33,0x36,0x34,0x36,0x2d,0x31,0x34,0x36,0x35,0x36,0x36,0x36,0x31,0x31,0x31,0xb,0x9,0x53,0x45,0x52,0x56,0x45,0x52,0x5f,0x4e,0x41,0x4d,0x45,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0xf,0x3,0x52,0x45,0x44,0x49,0x52,0x45,0x43,0x54,0x5f,0x53,0x54,0x41,0x54,0x55,0x53,0x32,0x30,0x30,0x3,0x20,0x50,0x57,0x44,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x61,0x70,0x61,0x63,0x68,0x65,0x2d,0x74,0x6f,0x6d,0x63,0x61,0x74,0x2d,0x37,0x2e,0x30,0x2e,0x32,0x8,0x15,0x48,0x4f,0x53,0x54,0x4e,0x41,0x4d,0x45,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x2e,0x6c,0x6f,0x63,0x61,0x6c,0x64,0x6f,0x6d,0x61,0x69,0x6e,0x7,0x3,0x43,0x56,0x53,0x5f,0x52,0x53,0x48,0x73,0x73,0x68,0xb,0x2b,0x48,0x54,0x54,0x50,0x5f,0x43,0x4f,0x4f,0x4b,0x49,0x45,0x4a,0x53,0x45,0x53,0x53,0x49,0x4f,0x4e,0x49,0x44,0x3d,0x44,0x41,0x35,0x30,0x34,0x33,0x35,0x44,0x45,0x46,0x38,0x31,0x36,0x37,0x41,0x46,0x30,0x46,0x30,0x33,0x42,0x46,0x35,0x41,0x32,0x44,0x41,0x32,0x43,0x32,0x34,0x45,0xb,0x9,0x53,0x45,0x52,0x56,0x45,0x52,0x5f,0x41,0x44,0x44,0x52,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x12,0x1,0x47,0x5f,0x42,0x52,0x4f,0x4b,0x45,0x4e,0x5f,0x46,0x49,0x4c,0x45,0x4e,0x41,0x4d,0x45,0x53,0x31,0xf,0x8,0x53,0x45,0x52,0x56,0x45,0x52,0x5f,0x50,0x52,0x4f,0x54,0x4f,0x43,0x4f,0x4c,0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x31,0x7,0x1d,0x4e,0x4c,0x53,0x50,0x41,0x54,0x48,0x2f,0x75,0x73,0x72,0x2f,0x64,0x74,0x2f,0x6c,0x69,0x62,0x2f,0x6e,0x6c,0x73,0x2f,0x6d,0x73,0x67,0x2f,0x25,0x4c,0x2f,0x25,0x4e,0x2e,0x63,0x61,0x74,0x14,0x1a,0x47,0x4e,0x4f,0x4d,0x45,0x5f,0x4b,0x45,0x59,0x52,0x49,0x4e,0x47,0x5f,0x53,0x4f,0x43,0x4b,0x45,0x54,0x2f,0x74,0x6d,0x70,0x2f,0x6b,0x65,0x79,0x72,0x69,0x6e,0x67,0x2d,0x61,0x6f,0x30,0x34,0x31,0x6a,0x2f,0x73,0x6f,0x63,0x6b,0x65,0x74,0x7,0xc,0x49,0x4e,0x50,0x55,0x54,0x52,0x43,0x2f,0x65,0x74,0x63,0x2f,0x69,0x6e,0x70,0x75,0x74,0x72,0x63,0x8,0x4,0x48,0x49,0x53,0x54,0x53,0x49,0x5a,0x45,0x31,0x30,0x30,0x30,0x15,0x4,0x58,0x5f,0x4a,0x41,0x56,0x41,0x42,0x52,0x49,0x44,0x47,0x45,0x5f,0x52,0x45,0x44,0x49,0x52,0x45,0x43,0x54,0x39,0x32,0x36,0x37,0xb,0x1e,0x53,0x43,0x52,0x49,0x50,0x54,0x5f,0x4e,0x41,0x4d,0x45,0x2f,0x4a,0x61,0x76,0x61,0x42,0x72,0x69,0x64,0x67,0x65,0x2f,0x73,0x65,0x73,0x73,0x69,0x6f,0x6e,0x53,0x68,0x61,0x72,0x69,0x6e,0x67,0x2e,0x70,0x68,0x70,0x4,0x5f,0x50,0x41,0x54,0x48,0x2f,0x75,0x73,0x72,0x2f,0x6b,0x65,0x72,0x62,0x65,0x72,0x6f,0x73,0x2f,0x62,0x69,0x6e,0x3a,0x2f,0x75,0x73,0x72,0x2f,0x6c,0x6f,0x63,0x61,0x6c,0x2f,0x62,0x69,0x6e,0x3a,0x2f,0x75,0x73,0x72,0x2f,0x62,0x69,0x6e,0x3a,0x2f,0x62,0x69,0x6e,0x3a,0x2f,0x75,0x73,0x72,0x2f,0x6c,0x6f,0x63,0x61,0x6c,0x2f,0x73,0x62,0x69,0x6e,0x3a,0x2f,0x75,0x73,0x72,0x2f,0x73,0x62,0x69,0x6e,0x3a,0x2f,0x73,0x62,0x69,0x6e,0x3a,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x62,0x69,0x6e,0xd,0x33,0x44,0x4f,0x43,0x55,0x4d,0x45,0x4e,0x54,0x5f,0x52,0x4f,0x4f,0x54,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x61,0x70,0x61,0x63,0x68,0x65,0x2d,0x74,0x6f,0x6d,0x63,0x61,0x74,0x2d,0x37,0x2e,0x30,0x2e,0x32,0x2f,0x77,0x65,0x62,0x61,0x70,0x70,0x73,0x2f,0x4a,0x61,0x76,0x61,0x42,0x72,0x69,0x64,0x67,0x65,0x13,0x1e,0x48,0x54,0x54,0x50,0x5f,0x41,0x43,0x43,0x45,0x50,0x54,0x5f,0x43,0x48,0x41,0x52,0x53,0x45,0x54,0x49,0x53,0x4f,0x2d,0x38,0x38,0x35,0x39,0x2d,0x31,0x2c,0x75,0x74,0x66,0x2d,0x38,0x3b,0x71,0x3d,0x30,0x2e,0x37,0x2c,0x2a,0x3b,0x71,0x3d,0x30,0x2e,0x37,0xb,0x9,0x52,0x45,0x4d,0x4f,0x54,0x45,0x5f,0x48,0x4f,0x53,0x54,0x31,0x32,0x37,0x2e,0x30,0x2e,0x30,0x2e,0x31,0xf,0xa,0x48,0x54,0x54,0x50,0x5f,0x43,0x4f,0x4e,0x4e,0x45,0x43,0x54,0x49,0x4f,0x4e,0x6b,0x65,0x65,0x70,0x2d,0x61,0x6c,0x69,0x76,0x65,0x9,0xe,0x48,0x54,0x54,0x50,0x5f,0x48,0x4f,0x53,0x54,0x6c,0x6f,0x63,0x61,0x6c,0x68,0x6f,0x73,0x74,0x3a,0x38,0x30,0x38,0x30,0x15,0x4,0x50,0x48,0x50,0x5f,0x46,0x43,0x47,0x49,0x5f,0x4d,0x41,0x58,0x5f,0x52,0x45,0x51,0x55,0x45,0x53,0x54,0x53,0x35,0x30,0x30,0x30,0x8,0xb,0x47,0x44,0x4d,0x5f,0x4c,0x41,0x4e,0x47,0x65,0x6e,0x5f,0x55,0x53,0x2e,0x55,0x54,0x46,0x2d,0x38,0xa,0x2c,0x58,0x41,0x55,0x54,0x48,0x4f,0x52,0x49,0x54,0x59,0x2f,0x76,0x61,0x72,0x2f,0x72,0x75,0x6e,0x2f,0x67,0x64,0x6d,0x2f,0x61,0x75,0x74,0x68,0x2d,0x66,0x6f,0x72,0x2d,0x66,0x65,0x64,0x6f,0x72,0x61,0x2d,0x36,0x62,0x4f,0x76,0x61,0x54,0x2f,0x64,0x61,0x74,0x61,0x62,0x61,0x73,0x65,0x14,0x3f,0x58,0x5f,0x4a,0x41,0x56,0x41,0x42,0x52,0x49,0x44,0x47,0x45,0x5f,0x43,0x4f,0x4e,0x54,0x45,0x58,0x54,0x36,0x40,0x25,0x32,0x46,0x68,0x6f,0x6d,0x65,0x25,0x32,0x46,0x66,0x65,0x64,0x6f,0x72,0x61,0x25,0x32,0x46,0x61,0x70,0x61,0x63,0x68,0x65,0x2d,0x74,0x6f,0x6d,0x63,0x61,0x74,0x2d,0x37,0x2e,0x30,0x2e,0x32,0x25,0x32,0x46,0x77,0x65,0x62,0x61,0x70,0x70,0x73,0x25,0x32,0x46,0x4a,0x61,0x76,0x61,0x42,0x72,0x69,0x64,0x67,0x65,0x8,0x6,0x55,0x53,0x45,0x52,0x4e,0x41,0x4d,0x45,0x66,0x65,0x64,0x6f,0x72,0x61,0xb,0x26,0x53,0x53,0x48,0x5f,0x41,0x53,0x4b,0x50,0x41,0x53,0x53,0x2f,0x75,0x73,0x72,0x2f,0x6c,0x69,0x62,0x65,0x78,0x65,0x63,0x2f,0x6f,0x70,0x65,0x6e,0x73,0x73,0x68,0x2f,0x67,0x6e,0x6f,0x6d,0x65,0x2d,0x73,0x73,0x68,0x2d,0x61,0x73,0x6b,0x70,0x61,0x73,0x73,0xf,0x66,0x48,0x54,0x54,0x50,0x5f,0x55,0x53,0x45,0x52,0x5f,0x41,0x47,0x45,0x4e,0x54,0x4d,0x6f,0x7a,0x69,0x6c,0x6c,0x61,0x2f,0x35,0x2e,0x30,0x20,0x28,0x58,0x31,0x31,0x3b,0x20,0x55,0x3b,0x20,0x4c,0x69,0x6e,0x75,0x78,0x20,0x69,0x36,0x38,0x36,0x3b,0x20,0x65,0x6e,0x2d,0x55,0x53,0x3b,0x20,0x72,0x76,0x3a,0x31,0x2e,0x39,0x2e,0x30,0x2e,0x34,0x29,0x20,0x47,0x65,0x63,0x6b,0x6f,0x2f,0x32,0x30,0x30,0x38,0x31,0x31,0x31,0x32,0x31,0x37,0x20,0x46,0x65,0x64,0x6f,0x72,0x61,0x2f,0x33,0x2e,0x30,0x2e,0x34,0x2d,0x31,0x2e,0x66,0x63,0x31,0x30,0x20,0x46,0x69,0x72,0x65,0x66,0x6f,0x78,0x2f,0x33,0x2e,0x30,0x2e,0x34,0x5,0x1,0x53,0x48,0x4c,0x56,0x4c,0x33,0xb,0x3f,0x48,0x54,0x54,0x50,0x5f,0x41,0x43,0x43,0x45,0x50,0x54,0x74,0x65,0x78,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x2c,0x61,0x70,0x70,0x6c,0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x2f,0x78,0x68,0x74,0x6d,0x6c,0x2b,0x78,0x6d,0x6c,0x2c,0x61,0x70,0x70,0x6c,0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x2f,0x78,0x6d,0x6c,0x3b,0x71,0x3d,0x30,0x2e,0x39,0x2c,0x2a,0x2f,0x2a,0x3b,0x71,0x3d,0x30,0x2e,0x38,0xf,0x3,0x48,0x54,0x54,0x50,0x5f,0x4b,0x45,0x45,0x50,0x5f,0x41,0x4c,0x49,0x56,0x45,0x33,0x30,0x30,0xf,0x1a,0x58,0x46,0x49,0x4c,0x45,0x53,0x45,0x41,0x52,0x43,0x48,0x50,0x41,0x54,0x48,0x2f,0x75,0x73,0x72,0x2f,0x64,0x74,0x2f,0x61,0x70,0x70,0x2d,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x73,0x2f,0x25,0x4c,0x2f,0x44,0x74,0x9,0xe,0x43,0x4f,0x4c,0x4f,0x52,0x54,0x45,0x52,0x4d,0x67,0x6e,0x6f,0x6d,0x65,0x2d,0x74,0x65,0x72,0x6d,0x69,0x6e,0x61,0x6c,0xf,0xa,0x53,0x45,0x52,0x56,0x45,0x52,0x5f,0x53,0x4f,0x46,0x54,0x57,0x41,0x52,0x45,0x4a,0x61,0x76,0x61,0x42,0x72,0x69,0x64,0x67,0x65,0x7,0x6,0x4c,0x4f,0x47,0x4e,0x41,0x4d,0x45,0x66,0x65,0x64,0x6f,0x72,0x61,0x8,0x8,0x57,0x49,0x4e,0x44,0x4f,0x57,0x49,0x44,0x36,0x35,0x30,0x33,0x36,0x36,0x33,0x34,0xf,0x46,0x53,0x43,0x52,0x49,0x50,0x54,0x5f,0x46,0x49,0x4c,0x45,0x4e,0x41,0x4d,0x45,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x61,0x70,0x61,0x63,0x68,0x65,0x2d,0x74,0x6f,0x6d,0x63,0x61,0x74,0x2d,0x37,0x2e,0x30,0x2e,0x32,0x2f,0x77,0x65,0x62,0x61,0x70,0x70,0x73,0x2f,0x4a,0x61,0x76,0x61,0x42,0x72,0x69,0x64,0x67,0x65,0x2f,0x73,0x65,0x73,0x73,0x69,0x6f,0x6e,0x53,0x68,0x61,0x72,0x69,0x6e,0x67,0x2e,0x70,0x68,0x70,0x1,0x22,0x5f,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x6a,0x72,0x65,0x31,0x2e,0x36,0x2e,0x30,0x5f,0x32,0x31,0x2f,0x2f,0x62,0x69,0x6e,0x2f,0x6a,0x61,0x76,0x61,0xa,0xe,0x58,0x4d,0x4f,0x44,0x49,0x46,0x49,0x45,0x52,0x53,0x40,0x69,0x6d,0x3d,0x69,0x6d,0x73,0x65,0x74,0x74,0x69,0x6e,0x67,0x73,0xe,0x3,0x52,0x45,0x51,0x55,0x45,0x53,0x54,0x5f,0x4d,0x45,0x54,0x48,0x4f,0x44,0x47,0x45,0x54,0xd,0x17,0x53,0x53,0x48,0x5f,0x41,0x55,0x54,0x48,0x5f,0x53,0x4f,0x43,0x4b,0x2f,0x74,0x6d,0x70,0x2f,0x6b,0x65,0x79,0x72,0x69,0x6e,0x67,0x2d,0x61,0x6f,0x30,0x34,0x31,0x6a,0x2f,0x73,0x73,0x68,0xf,0x6f,0x4c,0x44,0x5f,0x4c,0x49,0x42,0x52,0x41,0x52,0x59,0x5f,0x50,0x41,0x54,0x48,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x6a,0x72,0x65,0x31,0x2e,0x36,0x2e,0x30,0x5f,0x32,0x31,0x2f,0x6c,0x69,0x62,0x2f,0x69,0x33,0x38,0x36,0x2f,0x63,0x6c,0x69,0x65,0x6e,0x74,0x3a,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x6a,0x72,0x65,0x31,0x2e,0x36,0x2e,0x30,0x5f,0x32,0x31,0x2f,0x6c,0x69,0x62,0x2f,0x69,0x33,0x38,0x36,0x3a,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x6a,0x72,0x65,0x31,0x2e,0x36,0x2e,0x30,0x5f,0x32,0x31,0x2f,0x2e,0x2e,0x2f,0x6c,0x69,0x62,0x2f,0x69,0x33,0x38,0x36,0x11,0x1,0x50,0x48,0x50,0x5f,0x46,0x43,0x47,0x49,0x5f,0x43,0x48,0x49,0x4c,0x44,0x52,0x45,0x4e,0x35,0x5,0x9,0x53,0x48,0x45,0x4c,0x4c,0x2f,0x62,0x69,0x6e,0x2f,0x62,0x61,0x73,0x68,0x18,0x48,0x44,0x42,0x55,0x53,0x5f,0x53,0x45,0x53,0x53,0x49,0x4f,0x4e,0x5f,0x42,0x55,0x53,0x5f,0x41,0x44,0x44,0x52,0x45,0x53,0x53,0x75,0x6e,0x69,0x78,0x3a,0x61,0x62,0x73,0x74,0x72,0x61,0x63,0x74,0x3d,0x2f,0x74,0x6d,0x70,0x2f,0x64,0x62,0x75,0x73,0x2d,0x34,0x30,0x5a,0x45,0x48,0x6a,0x4b,0x63,0x62,0x62,0x2c,0x67,0x75,0x69,0x64,0x3d,0x33,0x32,0x38,0x33,0x62,0x38,0x37,0x39,0x30,0x34,0x61,0x37,0x31,0x61,0x37,0x65,0x33,0x38,0x34,0x31,0x33,0x61,0x31,0x34,0x34,0x63,0x38,0x31,0x34,0x63,0x65,0x35,0x11,0x4,0x47,0x4e,0x4f,0x4d,0x45,0x5f,0x4b,0x45,0x59,0x52,0x49,0x4e,0x47,0x5f,0x50,0x49,0x44,0x32,0x31,0x31,0x37,0xb,0x4,0x53,0x45,0x52,0x56,0x45,0x52,0x5f,0x50,0x4f,0x52,0x54,0x38,0x30,0x38,0x30,0xc,0x2d,0x47,0x54,0x4b,0x5f,0x52,0x43,0x5f,0x46,0x49,0x4c,0x45,0x53,0x2f,0x65,0x74,0x63,0x2f,0x67,0x74,0x6b,0x2f,0x67,0x74,0x6b,0x72,0x63,0x3a,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x2e,0x67,0x74,0x6b,0x72,0x63,0x2d,0x31,0x2e,0x32,0x2d,0x67,0x6e,0x6f,0x6d,0x65,0x32,0xb,0x9,0x52,0x45,0x4d,0x4f,0x54,0x45,0x5f,0x41,0x44,0x44,0x52,0x31,0x32,0x37,0x2e,0x30,0x2e,0x30,0x2e,0x31,0x8,0x19,0x4a,0x52,0x45,0x5f,0x48,0x4f,0x4d,0x45,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x2f,0x6a,0x72,0x65,0x31,0x2e,0x36,0x2e,0x30,0x5f,0x32,0x31,0x2f,0xf,0x5,0x44,0x45,0x53,0x4b,0x54,0x4f,0x50,0x5f,0x53,0x45,0x53,0x53,0x49,0x4f,0x4e,0x67,0x6e,0x6f,0x6d,0x65,0x7,0x4,0x44,0x49,0x53,0x50,0x4c,0x41,0x59,0x3a,0x30,0x2e,0x30,0x4,0x6,0x55,0x53,0x45,0x52,0x66,0x65,0x64,0x6f,0x72,0x61,0x4,0xc,0x48,0x4f,0x4d,0x45,0x2f,0x68,0x6f,0x6d,0x65,0x2f,0x66,0x65,0x64,0x6f,0x72,0x61,0x8,0x18,0x4c,0x45,0x53,0x53,0x4f,0x50,0x45,0x4e,0x7c,0x2f,0x75,0x73,0x72,0x2f,0x62,0x69,0x6e,0x2f,0x6c,0x65,0x73,0x73,0x70,0x69,0x70,0x65,0x2e,0x73,0x68,0x20,0x25,0x73,0x11,0x7,0x47,0x41,0x54,0x45,0x57,0x41,0x59,0x5f,0x49,0x4e,0x54,0x45,0x52,0x46,0x41,0x43,0x45,0x43,0x47,0x49,0x2f,0x31,0x2e,0x31,0x9,0x80,0x0,0x4,0x36,0x4c,0x53,0x5f,0x43,0x4f,0x4c,0x4f,0x52,0x53,0x6e,0x6f,0x3d,0x30,0x30,0x3a,0x66,0x69,0x3d,0x30,0x30,0x3a,0x64,0x69,0x3d,0x30,0x30,0x3b,0x33,0x34,0x3a,0x6c,0x6e,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x70,0x69,0x3d,0x34,0x30,0x3b,0x33,0x33,0x3a,0x73,0x6f,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x64,0x6f,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x62,0x64,0x3d,0x34,0x30,0x3b,0x33,0x33,0x3b,0x30,0x31,0x3a,0x63,0x64,0x3d,0x34,0x30,0x3b,0x33,0x33,0x3b,0x30,0x31,0x3a,0x6f,0x72,0x3d,0x34,0x30,0x3b,0x33,0x31,0x3b,0x30,0x31,0x3a,0x6d,0x69,0x3d,0x30,0x31,0x3b,0x30,0x35,0x3b,0x33,0x37,0x3b,0x34,0x31,0x3a,0x73,0x75,0x3d,0x33,0x37,0x3b,0x34,0x31,0x3a,0x73,0x67,0x3d,0x33,0x30,0x3b,0x34,0x33,0x3a,0x63,0x61,0x3d,0x33,0x30,0x3b,0x34,0x31,0x3a,0x74,0x77,0x3d,0x33,0x30,0x3b,0x34,0x32,0x3a,0x6f,0x77,0x3d,0x33,0x34,0x3b,0x34,0x32,0x3a,0x73,0x74,0x3d,0x33,0x37,0x3b,0x34,0x34,0x3a,0x65,0x78,0x3d,0x30,0x30,0x3b,0x33,0x32,0x3a,0x2a,0x2e,0x74,0x61,0x72,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x74,0x67,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x73,0x76,0x67,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x61,0x72,0x6a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x74,0x61,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x6c,0x7a,0x68,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x6c,0x7a,0x6d,0x61,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x7a,0x69,0x70,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x5a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x64,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x67,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x62,0x7a,0x32,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x74,0x62,0x7a,0x32,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x62,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x74,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x64,0x65,0x62,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x72,0x70,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x6a,0x61,0x72,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x72,0x61,0x72,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x61,0x63,0x65,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x7a,0x6f,0x6f,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x63,0x70,0x69,0x6f,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x37,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x72,0x7a,0x3d,0x30,0x30,0x3b,0x33,0x31,0x3a,0x2a,0x2e,0x6a,0x70,0x67,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6a,0x70,0x65,0x67,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x67,0x69,0x66,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x62,0x6d,0x70,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x70,0x62,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x70,0x67,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x70,0x70,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x74,0x67,0x61,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x78,0x62,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x78,0x70,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x74,0x69,0x66,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x74,0x69,0x66,0x66,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x70,0x6e,0x67,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x6e,0x67,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x70,0x63,0x78,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x6f,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x70,0x67,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x70,0x65,0x67,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x32,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x6b,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6f,0x67,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x70,0x34,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x34,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6d,0x70,0x34,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x76,0x6f,0x62,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x71,0x74,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x6e,0x75,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x77,0x6d,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x61,0x73,0x66,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x72,0x6d,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x72,0x6d,0x76,0x62,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x66,0x6c,0x63,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x61,0x76,0x69,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x66,0x6c,0x69,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x67,0x6c,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x64,0x6c,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x78,0x63,0x66,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x78,0x77,0x64,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x79,0x75,0x76,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x73,0x76,0x67,0x3d,0x30,0x30,0x3b,0x33,0x35,0x3a,0x2a,0x2e,0x61,0x61,0x63,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x61,0x75,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x66,0x6c,0x61,0x63,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x6d,0x69,0x64,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x6d,0x69,0x64,0x69,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x6d,0x6b,0x61,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x6d,0x70,0x33,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x6d,0x70,0x63,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x6f,0x67,0x67,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x72,0x61,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0x2a,0x2e,0x77,0x61,0x76,0x3d,0x30,0x30,0x3b,0x33,0x36,0x3a,0xf,0x11,0x4f,0x52,0x42,0x49,0x54,0x5f,0x53,0x4f,0x43,0x4b,0x45,0x54,0x44,0x49,0x52,0x2f,0x74,0x6d,0x70,0x2f,0x6f,0x72,0x62,0x69,0x74,0x2d,0x66,0x65,0x64,0x6f,0x72,0x61,0xb,0x1e,0x52,0x45,0x51,0x55,0x45,0x53,0x54,0x5f,0x55,0x52,0x49,0x2f,0x4a,0x61,0x76,0x61,0x42,0x72,0x69,0x64,0x67,0x65,0x2f,0x73,0x65,0x73,0x73,0x69,0x6f,0x6e,0x53,0x68,0x61,0x72,0x69,0x6e,0x67,0x2e,0x70,0x68,0x70,0x4,0xb,0x4c,0x41,0x4e,0x47,0x65,0x6e,0x5f,0x55,0x53,0x2e,0x55,0x54,0x46,0x2d,0x38,0x1,0x4,0x0,0x1,0x0,0x0,0x0,0x0,0x1,0x5,0x0,0x1,0x0,0x0,0x0,0x0);
$dataStr="";
for($i=0; $i<count($data); $i++) {
  $dataStr.=chr($data[$i]);
}

$fp = fsockopen("127.0.0.1", 9667, &$errno, &$errstr) or die("fsockopen");
for ($k=0; $k<100; $k++) {
  fwrite($fp, $dataStr) or die("send");
  $n=10536;
  do {
    $c=strlen(fread($fp, $n));
    if (feof($fp)) die("fread");
    $n-=$c;
  } while($n>0);
}
fclose($fp);
-----------end of ack_delay.php------------

REDIRECT_STATUS="200" PHP_FCGI_CHILDR="5" PHP_FCGI_MAX_REQUESTS="50000" ~/php-cgi533.patched -b 127.0.0.1:9667

#unpatched
time ~/php ack_delay.php
real	0m4.135s
user	0m0.020s
sys	0m0.023s

#patched
real	0m0.140s
user	0m0.022s
sys	0m0.028s

Which means php fastcgi > 5.1.4 is more 30 times slower than 5.1.4.

To reproduce: http://sourceforge.net/projects/php-java-bridge/files/RHEL_FC%20SecurityEnhancedLinux/php-java-bridge_6.2.1rc2/

PHP test script created from: http://php-java-bridge.cvs.sourceforge.net/viewvc/php-java-bridge/php-java-bridge/server/php/java/bridge/http/FCGIConnectionOutputStream.java?revision=1.2&view=markup&sortby=date and http://php-java-bridge.cvs.sourceforge.net/viewvc/php-java-bridge/php-java-bridge/server/php/java/bridge/http/FCGIConnectionInputStream.java?revision=1.2&view=markup&sortby=date

Test system: Fedora 10, Linux kernel 
Linux version 2.6.27.5-117.fc10.i686 (mockbuild@x86-7.fedora.phx.redhat.com) (gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC) ) #1 SMP Tue Nov 18 12:19:59 EST 2008



> I don't know what is the "ack delay". As I know TCP_NODELAY just disables the > Nagle algorithm and this makes packets to be always sent ASAP. As result it 
> may produce more packets. Probably it may affect FastCGI only in some 
> specific scenarios.

Please see http://en.wikipedia.org/wiki/Nagle%27s_algorithm

"With both algorithms enabled, applications which do two successive writes to a TCP connection, followed by a read which will not be fulfilled until after the data from the second write has reached the destination, experience a constant delay of up to 500 milliseconds, the "ACK delay"."


Regards,
Jost Bökemeier
 [2010-09-02 14:35 UTC] dmitry@php.net
Thanks a lot. Now I'm able to reproduce the issie.

It occurs only in case of persistent FastCGI connections (byte number 11 in you array is 1) and large output.

Unfortunately, your patch didn't fix the bug. From time to time 1/10000 strace shows huge delay (up to 30 sec) on write() syscall.

netstat -neo

Proto Recv-Q Send-Q Local Address   Foreign Address State       Timer
tcp    90501 277632 127.0.0.1:1234  127.0.0.1:59195 ESTABLISHED probe (1.11/0/0)
tcp   556640 118784 127.0.0.1:59195 127.0.0.1:1234  ESTABLISHED probe (0.88/0/0)

I'll think about it.
 [2010-09-02 17:22 UTC] dmitry@php.net
Also, which web server and fastcgi manager do you use?
 [2010-09-04 11:33 UTC] jost_boekemeier at users dot sf dot net
> Also, which web server 

A Java servlet. It uses a persistent fcgi connection and establishes a new connection after FCGI_MAX_REQUESTS. 


> and fastcgi manager do you use?

Usually php-cgi. Some people are currently using the software with PHP's new new fcgi manager, but I don't have any experience with that.


> strace shows huge delay (up to 30 sec) on write() syscal

Could be some other problem, probably not related to PHP. MAX_REQUESTS reached or a kernel bug or something. 

Although NDELAY isn't an elegant solution, the alternative, a 64K write buffer, may cause more problems. Is 64k enough these days?
 [2010-09-06 13:11 UTC] dmitry@php.net
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=303072
Log: Fixed bug #46723 (FastCGI persistent connection is incredibly slow due to TCP ack delay).
 [2010-09-13 13:42 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2010-09-13 13:42 UTC] dmitry@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC