PHP使用rdkafka生成挂起100ms的消息

时间:2017-12-23 13:25:16

标签: php apache-kafka

当我在php中使用rdkafka产生消息时,该程序将挂起100ms

我的代码参考是这个网站https://switchcaseblog.wordpress.com/2017/01/20/how-to-get-php-and-kafka-to-play-nicely-and-not-do-it-slowly/

php版本: PHP 7.0.13

rdkafka版本:

version => 3.0.5
build date => Dec 23 2017 20:38:03
librdkafka version (runtime) => 0.11.3

生成配置

'request.required.acks' => 0,
'message.timeout.ms' => 300,
'queue.buffering.max.ms' => 1,
'message.max.bytes' => 3000000,
'socket.keepalive.enable' => true

所以我对php进程进行了分析,代码如下:

21:05:07.395746 fcntl(4, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=1}) = 0
21:05:07.395799 fcntl(4, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=1}) = 0
21:05:07.395828 munmap(0x7f9036659000, 1106) = 0
21:05:07.395853 close(5)                = 0
21:05:07.396263 futex(0x7f902be5e580, FUTEX_WAKE_PRIVATE, 2147483647) = 0
21:05:07.396484 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
21:05:07.396531 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f900641a000
21:05:07.396577 mprotect(0x7f900641a000, 4096, PROT_NONE) = 0
21:05:07.396614 clone(child_stack=0x7f9006e19e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f9006e1a9d0, tls=0x7f9006e1a700, child_tidptr=0x7f9006e1a9d0) = 22018
21:05:07.396696 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0
21:05:07.396764 pipe([5, 6])            = 0
21:05:07.396833 fcntl(5, F_GETFL)       = 0 (flags O_RDONLY)
21:05:07.396858 fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
21:05:07.396880 fcntl(6, F_GETFL)       = 0x1 (flags O_WRONLY)
21:05:07.396902 fcntl(6, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
21:05:07.396926 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f9005a19000
21:05:07.396962 mprotect(0x7f9005a19000, 4096, PROT_NONE) = 0
21:05:07.397013 clone(child_stack=0x7f9006418e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f90064199d0, tls=0x7f9006419700, child_tidptr=0x7f90064199d0) = 22019
21:05:07.397107 rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], NULL, 8) = 0
21:05:07.397137 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
21:05:07.397191 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
21:05:07.397219 pipe([7, 8])            = 0
21:05:07.397245 fcntl(7, F_GETFL)       = 0 (flags O_RDONLY)
21:05:07.397268 fcntl(7, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
21:05:07.397290 fcntl(8, F_GETFL)       = 0x1 (flags O_WRONLY)
21:05:07.397311 fcntl(8, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
21:05:07.397335 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f9005018000
21:05:07.397372 mprotect(0x7f9005018000, 4096, PROT_NONE) = 0
21:05:07.397421 clone(child_stack=0x7f9005a17e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f9005a189d0, tls=0x7f9005a18700, child_tidptr=0x7f9005a189d0) = 22020
21:05:07.397469 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
21:05:07.397507 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
21:05:07.397534 pipe([9, 10])           = 0
21:05:07.397560 fcntl(9, F_GETFL)       = 0 (flags O_RDONLY)
21:05:07.397582 fcntl(9, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
21:05:07.397604 fcntl(10, F_GETFL)      = 0x1 (flags O_WRONLY)
21:05:07.397626 fcntl(10, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
21:05:07.397650 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f9004616000
21:05:07.397687 mprotect(0x7f9004616000, 4096, PROT_NONE) = 0
21:05:07.397733 clone(child_stack=0x7f9005015e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f90050169d0, tls=0x7f9005016700, child_tidptr=0x7f90050169d0) = 22021
21:05:07.397781 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
21:05:07.398147 write(1, "\350\200\227\346\227\2666\346\257\253\347\247\222", 13耗时6毫秒) = 13
21:05:07.398203 write(1, "\n", 1
)       = 1
21:05:07.398318 close(2)                = 0
21:05:07.398347 close(1)                = 0
21:05:07.398372 munmap(0x7f903665a000, 4096) = 0
21:05:07.398433 close(0)                = 0
21:05:07.398456 munmap(0x7f903665b000, 4096) = 0
21:05:07.398490 futex(0x212e19c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, {1514034307, 399482000}, ffffffff) = -1 ETIMEDOUT (Connection timed out)
21:05:07.399575 futex(0x212e170, FUTEX_WAKE_PRIVATE, 1) = 0
21:05:07.399602 futex(0x212e19c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 3, {1514034307, 400596000}, ffffffff) = -1 ETIMEDOUT (Connection timed out)
21:05:07.400684 futex(0x212e170, FUTEX_WAKE_PRIVATE, 1) = 0
21:05:07.400710 futex(0x212e19c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 5, {1514034307, 401704000}, ffffffff) = 0
21:05:07.401209 futex(0x212e170, FUTEX_WAKE_PRIVATE, 1) = 0
21:05:07.401268 futex(0x212e25c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x212e258, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
21:05:07.401316 futex(0x7f9006e1a9d0, FUTEX_WAIT, 22018, NULL) = 0
21:05:07.502855 munmap(0x7f8ff75ff000, 10489856) = 0
21:05:07.503046 fcntl(4, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=0}) = 0
21:05:07.503295 munmap(0x7f9006e1b000, 67108864) = 0
21:05:07.503417 close(4)                = 0
21:05:07.503530 munmap(0x7f902be63000, 2182736) = 0
21:05:07.503580 munmap(0x7f902bbac000, 2844152) = 0
21:05:07.503662 munmap(0x7f902c078000, 2186600) = 0
21:05:07.503776 munmap(0x7f902c954000, 2129096) = 0
21:05:07.503811 munmap(0x7f902c740000, 2176864) = 0
21:05:07.503842 munmap(0x7f902c503000, 2343352) = 0
21:05:07.503891 munmap(0x7f902c28e000, 2574912) = 0
21:05:07.503939 munmap(0x3e5ea00000, 2109528) = 0
21:05:07.503988 munmap(0x7f902cb5c000, 2111520) = 0
21:05:07.504095 munmap(0x7f902cd60000, 2108464) = 0
21:05:07.504151 munmap(0x7f902cf63000, 2129280) = 0
21:05:07.504242 munmap(0x7f902d7ec000, 2155960) = 0
21:05:07.504277 munmap(0x7f902d581000, 2533392) = 0
21:05:07.504332 munmap(0x7f902d9fb000, 2163080) = 0
21:05:07.504421 munmap(0x7f900ae1b000, 2113976) = 0
21:05:07.504479 munmap(0x7f900b020000, 2113944) = 0
21:05:07.504524 munmap(0x7f900b225000, 2126432) = 0
21:05:07.504560 munmap(0x7f900b42d000, 2113976) = 0
21:05:07.504601 munmap(0x7f900b9a6000, 2117960) = 0
21:05:07.504630 munmap(0x7f900b632000, 3618944) = 0
21:05:07.504668 futex(0x7f902dedc040, FUTEX_WAKE_PRIVATE, 2147483647) = 0
21:05:07.504712 munmap(0x7f902dc0c000, 2956168) = 0
21:05:07.504857 munmap(0x7f902e8b1000, 2514584) = 0
21:05:07.504918 munmap(0x7f902e58d000, 3293152) = 0
21:05:07.504966 munmap(0x7f902e0eb000, 4856016) = 0
21:05:07.505086 munmap(0x7f902dede000, 2150272) = 0
21:05:07.505151 munmap(0x7f902ed31000, 2144104) = 0
21:05:07.505194 munmap(0x7f902eb17000, 2202200) = 0

strace -c php scritp.php

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 95.15    0.001000          59        17         3 futex
  4.85    0.000051           0       742       615 open
  0.00    0.000000           0        97           read
  0.00    0.000000           0         9           write
  0.00    0.000000           0       129           close
  0.00    0.000000           0        77        49 stat
  0.00    0.000000           0       148           fstat
  0.00    0.000000           0        57         1 lstat
  0.00    0.000000           0         2           poll
  0.00    0.000000           0         8         3 lseek
  0.00    0.000000           0       259         1 mmap
  0.00    0.000000           0       127           mprotect

Futex需要大约100ms,如何解决

谁能帮帮我?感谢谁能帮忙解答下,哈哈

0 个答案:

没有答案