在Golang中多次请求unix管道(sockerpair)通信时读/写管道延迟

时间:2016-10-31 17:56:03

标签: linux unix go pipe socketpair

我在Golang中遇到了sockerpair的性能问题(也称为unix管道进程间通信)。

如果向管道发出许多请求,延迟将会很长。一个进程发出大约10K个请求;然后管道(sockerpair阅读器)的阅读器过程将长时间停滞不前。现在,我正在使用syscall.read()syscall.write()

有什么建议我可以改善管道中的读取延迟吗?我已尝试使用syscall.Recvmsgsyscall.Sendmsg,但他们在这里没有帮助,因为我不熟悉如何正确设置标记。

以下是stace日志,对于每一行,第一个元素是PID,第二个元素是花在这个指令上的时间,第三个是进程的处理程序,第四个是操作:< / p>

正常的:

**13151** 0.000020 [00000000004f23c4] read(8, 
13496 0.000023 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 3} 
13149 0.000020 [000000000046bc07] <... select resumed> ) = 0 (Timeout) <0.000104>
13149 0.000026 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20} 
13496 0.000044 [000000000046bc07] <... select resumed> ) = 0 (Timeout) <0.000077>
13496 0.000022 [000000000046c023] futex(0xc4204ae110, FUTEX_WAKE, 1) = 1 <0.000018>
13495 0.000047 [000000000046c023] <... futex resumed> ) = 0 <0.021090>
13149 0.000012 [000000000046bc07] <... select resumed> ) = 0 (Timeout) <0.000117>
13495 0.000063 [000000000046c023] futex(0xc4204ae110, FUTEX_WAIT, 0, NULL 
13496 0.000033 [00000000004f23c4] write(2, "2016/10/21 17:31:35 [/0-0] flush"..., 55 
13149 0.000023 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20} 
13496 0.000039 [00000000004f23c4] <... write resumed> ) = 55 <0.000044>
13496 0.000030 [00000000004f23c4] write(8, "\20\0\0\0\0\0\0\0a\0\0\0\0\0\0\0", 16) = 16 <0.000023>
13149 0.000042 [000000000046bc07] <... select resumed> ) = 0 (Timeout) <0.000100>
13496 0.000022 [000000000046c023] futex(0xc4204b8110, FUTEX_WAIT, 0, NULL 
**13151** 0.000016 [00000000004f23c4] <... read resumed> "@\0\0\0\22\0\0\0b\0\0\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 135168) = 64 <0.000456>

异常(或长延迟):

13151 0.000005 [00000000004f23c4] read(8, 
13153 0.000008 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 3} 
13149 0.000010 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20} 
13153 0.000061 [000000000046bc07] <... select resumed> ) = 0 (Timeout) <0.000064>
13153 0.000012 [000000000046c023] futex(0xc42007a910, FUTEX_WAKE, 1) = 1 <0.000010>
13158 0.000020 [000000000046c023] <... futex resumed> ) = 0 <0.031368>
13149 0.000008 [000000000046bc07] <... select resumed> ) = 0 (Timeout) <0.000095>
13158 0.000013 [000000000046c023] futex(0xc42007a910, FUTEX_WAIT, 0, NULL 
13153 0.000006 [00000000004f23c4] write(8, "\20\0\0\0\332\377\377\377\n\0\0\0\0\0\0\0", 16 
13149 0.000008 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20} 
13153 0.000020 [00000000004f23c4] <... write resumed> ) = 16 <0.000022>
13153 0.000028 [000000000046c023] futex(0xc4200e0110, FUTEX_WAIT, 0, NULL 
13149 0.000054 [000000000046bc07] <... select resumed> ) = 0 (Timeout) <0.000085>
13149 0.000013 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20}) = 0 (Timeout) <0.000084>
13149 0.000100 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20}) = 0 (Timeout) <0.000083>
13149 0.000098 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20}) = 0 (Timeout) <0.000083>
13149 0.000099 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 20}) = 0 (Timeout) <0.000083>
...... A lot more same record happens here.
13149 0.000721 [000000000046bc07] select(0, NULL, NULL, NULL, {0, 1280}) = 0 (Timeout) <0.001344>
13149 0.000098 [000000000046c023] futex(0x745b78, FUTEX_WAIT, 0, {60, 0} 
13151 30.186205 [00000000004f23c4] <... read resumed> "P\0\2\0\20\0\0\0\v\0\0\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 135168) = 131152 <30.201482>

0 个答案:

没有答案