php-nats-streaming icon indicating copy to clipboard operation
php-nats-streaming copied to clipboard

Very important setting for performance

Open sazo opened this issue 6 years ago • 5 comments

After 1.5 weeks of debugging (yes i kind you not) i found the stream socket setting 'tcp_nodelay' to be very important for performance.

See http://php.net/manual/en/context.socket.php

With tcp_nodelay set to false

php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.12199187278748 :       TLS connecting"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: Subscribing to heartbeat Inbox _INBOX.5be973f68b1f9"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.0010449886322021 :       Preparing data for client connect"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 8.8930130004883E-5 :       Subscribing for ConnectResponse"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.00017595291137695 :       Auto unscribing after 1 message is received"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.00022983551025391 :       Discovery"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.00027894973754883 :       After Discovery"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.04311203956604 :         Received ConnectResponse"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.04382586479187 :         After wait"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.043874025344849 :         Connect Request"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.16754603385925 :       Connecting"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.0039598941802979 :         Dispatch send request"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.17437696456909 :       Sending email"
php-fpm_1                 | 172.151.0.6 -  12/Nov/2018:12:37:10 +0000 "GET /index.php" 302
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: Closing down"
php-fpm_1                 | [12-Nov-2018 12:37:10] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: Closing down"

With tcp_nodelay set to true

php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.074014902114868 :       TLS connecting"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: Subscribing to heartbeat Inbox _INBOX.5be974612a673"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.00038790702819824 :       Preparing data for client connect"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 7.319450378418E-5 :       Subscribing for ConnectResponse"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.0001671314239502 :       Auto unscribing after 1 message is received"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.00023007392883301 :       Discovery"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.00029301643371582 :       After Discovery"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.0010581016540527 :         Received ConnectResponse"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.0013542175292969 :         After wait"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.0013811588287354 :         Connect Request"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.076140165328979 :       Connecting"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.0015089511871338 :         Dispatch send request"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: 0.079082012176514 :       Sending email"
php-fpm_1                 | 172.151.0.6 -  12/Nov/2018:12:38:56 +0000 "GET /index.php" 302
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: Closing down"
php-fpm_1                 | [12-Nov-2018 12:38:57] WARNING: [pool www] child 21 said into stderr: "NOTICE: PHP message: Closing down"

Cut down response time by ~100MS

sazo avatar Nov 12 '18 12:11 sazo

@sazo nice catch! I rely on phpnats so once the fix is made there then one can set that with the options here.

byrnedo avatar Nov 14 '18 14:11 byrnedo

it looks like maintainer has left project(

fizzka avatar Jan 08 '19 21:01 fizzka

@fizzka we ended up forking this repo and the main nats repo. :) We are planing implementing non-blocking socket stream for performance reasons

sazo avatar Jan 09 '19 13:01 sazo

@sazo It'd be great if you wanted to make a pull request with those changes in both?

byrnedo avatar Jan 09 '19 13:01 byrnedo

@sazo Could you please tell me how to set it? Thanks!

AlanSyue avatar Jul 06 '22 00:07 AlanSyue