目前发现两大问题:
1. GOGC,关闭Garbage Collection,性能提高20%,无语了,golang不是吹牛GC比JVM
G1强很多么?NGINX不用GC不是照样可以写程序么?
2. 滥用FUTEX,从strace上看,一个HTTP GET引发众多threads拼抢,thundering herd
problem,跟NGINX的SO_REUSEPORT设计完全不同。GO runtime调度需要用futex,众多
goroutines给本来就很脆弱的futex加重负担。
各位大侠,我没学过golang,只花了几天测测http性能,就发现这两个问题,这应该是
设计失误吧?
[pid 29063] <... epoll_wait="" resumed=""> [{EPOLLIN|EPOLLOUT, {u32=4228357504,
u64=140170486062464}}], 128, -1) = 1
[pid 29063] futex(0x147c010, FUTEX_WAKE, 1) = 1
[pid 29063] read(6,
[pid 29010] <... futex="" resumed=""> ) = 0
[pid 29063] <... read="" resumed=""> "GET /1kb HTTP/1.1\r\nHost: dx-1"..., 4096) =
1316
[pid 29010] pselect6(0, NULL, NULL, NULL, {tv_sec=0, tv_nsec=20000}, NULL <
unfinished ...>
[pid 29063] futex(0x1481040, FUTEX_WAKE, 1) = 1
[pid 29977] <... futex="" resumed=""> ) = 0
[pid 29977] futex(0x1481040, FUTEX_WAIT, 0, {tv_sec=0, tv_nsec=994743017} <
unfinished ...>
[pid 29010] <... pselect6="" resumed=""> ) = 0 (Timeout)
[pid 29063] futex(0x1481040, FUTEX_WAKE, 1
[pid 29010] pselect6(0, NULL, NULL, NULL, {tv_sec=0, tv_nsec=20000}, NULL <
unfinished ...>
[pid 29977] <... futex="" resumed=""> ) = 0
[pid 29063] <... futex="" resumed=""> ) = 1
[pid 29977] sched_yield(
[pid 29063] futex(0xc42434c148, FUTEX_WAKE, 1
[pid 29977] <... resumed="" sched_yield=""> ) = 0
[pid 29063] <... futex="" resumed=""> ) = 1
[pid 29977] futex(0x1481020, FUTEX_WAKE, 1
[pid 29063] futex(0x1481040, FUTEX_WAKE, 1
[pid 29977] <... futex="" resumed=""> ) = 0
[pid 29063] <... futex="" resumed=""> ) = 0
[pid 29977] sched_yield(
[pid 29019] <... futex="" resumed=""> ) = 0
[pid 29977] <... resumed="" sched_yield=""> ) = 0
[pid 29019] epoll_wait(4,
[pid 29977] futex(0x1481020, FUTEX_WAKE, 1
[pid 29019] <... epoll_wait="" resumed=""> [], 128, 0) = 0
[pid 29977] <... futex="" resumed=""> ) = 0
[pid 29063] write(6, "HTTP/1.1 200 OK\r\nAccept-Ranges: "..., 1444 <
unfinished ...>
[pid 29977] futex(0x1481040, FUTEX_WAIT, 0, {tv_sec=9, tv_nsec=999836825} <
unfinished ...>
[pid 29019] futex(0xc432ddc948, FUTEX_WAKE, 1
[pid 29063] <... resumed="" write=""> ) = 1444
[pid 29019] <... futex="" resumed=""> ) = 1
[pid 29063] futex(0x1481040, FUTEX_WAKE, 1
[pid 29010] <... pselect6="" resumed=""> ) = 0 (Timeout)
[pid 29977] <... futex="" resumed=""> ) = 0
[pid 29063] <... futex="" resumed=""> ) = 1
[pid 29977] sched_yield(
[pid 29062] <... futex="" resumed=""> ) = 0
[pid 29977] <... resumed="" sched_yield=""> ) = 0
[pid 29063] read(6,
[pid 29977] futex(0x1481020, FUTEX_WAKE, 1
[pid 29063] <... read="" resumed=""> 0xc42ed24000, 4096) = -1 EAGAIN (Resource
temporarily unavailable)
[pid 29977] <... futex="" resumed=""> ) = 0
[pid 29063] epoll_wait(4,
[pid 29977] futex(0x1481040, FUTEX_WAIT, 0, {tv_sec=9, tv_nsec=999668369} <
unfinished ...>
[pid 29063] <... epoll_wait="" resumed=""> [], 128, 0) = 0
[pid 29062] epoll_wait(4,
[pid 29063] epoll_wait(4,
[pid 29062] <... epoll_wait="" resumed=""> [], 128, 0) = 0
[pid 29019] epoll_wait(4,
[pid 29062] futex(0xc432ddc948, FUTEX_WAIT, 0, NULL
[pid 29019] <... epoll_wait="" resumed=""> [], 128, 0) = 0
[pid 29010] pselect6(0, NULL, NULL, NULL, {tv_sec=0, tv_nsec=20000}, NULL <
unfinished ...>
[pid 29019] futex(0xc42434c148, FUTEX_WAIT, 0, NULL
[pid 29010] <... pselect6="" resumed=""> ) = 0 (Timeout)
[pid 29010] futex(0x147c010, FUTEX_WAIT, 0, {tv_sec=60, tv_nsec=0} <
unfinished ...>
[pid 29977] <... futex="" resumed=""> ) = -1 ETIMEDOUT (Connection timed out)
[pid 29977] futex(0x147c010, FUTEX_WAKE, 1) = 1
[pid 29977] futex(0x1481040, FUTEX_WAIT, 0, {tv_sec=0, tv_nsec=15876} <
unfinished ...>
[pid 29010] <... futex="" resumed=""> ) = 0
[pid 29010] pselect6(0, NULL, NULL, NULL, {tv_sec=0, tv_nsec=20000}, NULL <
unfinished ...>
[pid 29977] <... futex="" resumed=""> ) = -1 ETIMEDOUT (Connection timed out)
[pid 29977] futex(0xc42434c148, FUTEX_WAKE, 1) = 1
[pid 29019] <... futex="" resumed=""> ) = 0
[pid 29977] futex(0xc432ddc948, FUTEX_WAKE, 1
[pid 29019] futex(0xc4340ffd48, FUTEX_WAKE, 1
[pid 29977] <... futex="" resumed=""> ) = 1
[pid 29062] <... futex="" resumed=""> ) = 0
[pid 29977] futex(0x1481040, FUTEX_WAIT, 0, {tv_sec=5, tv_nsec=730378996} <
unfinished ...>
[pid 29062] futex(0xc432ddc948, FUTEX_WAIT, 0, NULL
[pid 29508] <... futex="" resumed=""> ) = 0
[pid 29019] <... futex="" resumed=""> ) = 1
[pid 29508] futex(0xc4340ffd48, FUTEX_WAIT, 0, NULL
[pid 29010] <... pselect6="" resumed=""> ) = 0 (Timeout)
[pid 29019] epoll_ctl(4, EPOLL_CTL_DEL, 6, 0xc43657db64) = 0
[pid 29010] pselect6(0, NULL, NULL, NULL, {tv_sec=0, tv_nsec=20000}, NULL <
unfinished ...>
[pid 29019] close(6) = 0
[pid 29019] futex(0xc4340ffd48, FUTEX_WAKE, 1) = 1
[pid 29010] <... pselect6="" resumed=""> ) = 0 (Timeout)
[pid 29019] futex(0xc42434c148, FUTEX_WAIT, 0, NULL
[pid 29508] <... futex="" resumed=""> ) = 0
[pid 29010] pselect6(0, NULL, NULL, NULL, {tv_sec=0, tv_nsec=20000}, NULL <
unfinished ...>
[pid 29508] futex(0xc4340ffd48, FUTEX_WAIT, 0, NULL
[pid 29010] <... pselect6="" resumed=""> ) = 0 (Timeout)
[pid 29010] futex(0x147c010, FUTEX_WAIT, 0, {tv_sec=60, tv_nsec=0} <
unfinished ...>