Upload
cs-center
View
65
Download
3
Embed Size (px)
Citation preview
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.1/18
Blazing fast native IO in Java
Толстопятов ВсеволодSegmento
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.2/18
Что происходит?
▶ RTB engine, up to 100k RPS▶ Soft real-time, latency sensitive▶ Server-server, client-server streams▶ I/O bound1
1Кроме тех случаев, когда нет
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.3/18
Что происходит?
▶ RTB engine, up to 100k RPS▶ Soft real-time, latency sensitive▶ Server-server, client-server streams▶ I/O bound▶ NIO? Current implementation: 12k RPS, garbage,queues, locks
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.4/18
Что происходит?
▶ RTB engine, up to 100k RPS▶ Soft real-time, latency sensitive▶ Server-server, client-server streams▶ I/O bound▶ NIO? Current implementation: 12k RPS, garbage,queues, locks
▶ Надо что-то делать
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.5/18
NIO puzzle
Сколько локов захватывается в процессе переходаacceptable -> readable при использованииjava.nio.channels.Selector?
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.6/18
NIO puzzle
Сколько локов захватывается в процессе переходаacceptable -> readable при использованииjava.nio.channels.Selector?
▶ 6-9 на select()▶ Еще 3 на accept()▶ 4 на register()
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.7/18
NIO puzzle
Сколько локов захватывается в процессе переходаacceptable -> readable при использованииjava.nio.channels.Selector?
▶ 6-9 на select()▶ Еще 3 на accept()▶ 4 на register()▶ Все еще не потокобезопасен!
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.8/18
Ну вы поняли
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.9/18
А если серьезно
▶ Finalizable sockets▶ Compatibility issues (no custom socket options)▶ No epoll▶ Too old▶ Artificial limitations (selection keys, blockingselector, locks)
▶ GC pressure, concurrent queues , death and despair
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.10/18
Что делать?
▶ JNI library inspired by Netty/Tomcat native▶ Edge-triggered epoll▶ Reactor, fixed threading model▶ Lightweight, no ssl▶ Custom socket options
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.11/18
Tips and tricks
▶ Cache jmethodID/jfieldID▶ Threads affinity▶ Blocking mode with epoll2▶ Reusable buffers (G1 is shining)▶ TCP_DEFER_ACCEPT, TCP_NO_DELAY/TCP_CORK [,SO_REUSE_PORT, TCP_NOTSENT_LOWAT]
▶ Java fallback: reflection hacks, biased locking,JCTools queues
2Paul Tyma: Thousands of Threads and Blocking I/O
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.12/18
Нагружаем
▶ Yandex.Tank▶ CentOS▶ HdrHistogram▶ Local/outer network interfaces▶ irqbalance, no tuning▶ Blocking/non-blocking modes, TCP_*
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.13/18
Графики vs baseline
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.14/18
Графики. Scaling
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.15/18
Результат
▶ Ненависть к JNI▶ Faster, better, stronger▶ OS-tuning bound▶ Huge tuning space (650k Akka over Aeron)▶ Evaluate integration to core▶ Bunch of things to do
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.16/18
Q & A
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.17/18
Netty
▶ Dependency hell, compatibility issues▶ Event-driven model (queues and on*() everywhere)▶ Bunch of garbage▶ ByteBuf problems (till jemalloc)▶ Netty is nice▶ Netty native is awesome
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.
...
.18/18
Epoll
▶ sun.nio.ch.EPollSelectorImpl :(▶ Level-triggered (aka repeatable)▶ Internal magic: using fake FD and workarounds▶ Still NIO