Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Chicago

Slide 3

Slide 3 text

Agenda πŸ“ About me πŸ“ Netty project πŸ“ Netty in action

Slide 4

Slide 4 text

About me Portland Oregon Java since 1996 open source contributor

Slide 5

Slide 5 text

Netty contributor

Slide 6

Slide 6 text

βœ… async-http-client βœ… reactor-netty βœ… Netflix Zuul βœ… Apache Pinot

Slide 7

Slide 7 text

Netty is open source

Slide 8

Slide 8 text

Netty at Netflix Netty Zuul AWS Cassandra Netty

Slide 9

Slide 9 text

Zuul is built on Netty

Slide 10

Slide 10 text

Zuul: Server.java

Slide 11

Slide 11 text

Zuul server channel initializer

Slide 12

Slide 12 text

Zuul channel handlers

Slide 13

Slide 13 text

Zuul push messaging

Slide 14

Slide 14 text

Zuul push messaging

Slide 15

Slide 15 text

Zuul: sendPushMessage

Slide 16

Slide 16 text

Cassandra is built on Netty

Slide 17

Slide 17 text

Cassandra: SocketFactory.java

Slide 18

Slide 18 text

β€œNetty is an asynchronous event-driven network application framework”

Slide 19

Slide 19 text

πŸ“ Apache ActiveMQ Artemis πŸ“ Apache Bookkeeper πŸ“ Apache Camel πŸ“ Apache Cassandra πŸ“ Apache CXF πŸ“ Apache Druid

Slide 20

Slide 20 text

πŸ“ Apache Flink πŸ“ Apache NiFi πŸ“ Apache Pinot πŸ“ Apache Pulsar πŸ“ Apache Spark πŸ“ Apache Zookeeper

Slide 21

Slide 21 text

πŸ“ Armeria πŸ“ Micronaut πŸ“ Netflix Zuul πŸ“ OpenSearch

Slide 22

Slide 22 text

And many others… πŸ“ Apple Servicetalk πŸ“ Azure SDK for Java πŸ“ AWS SDK for Java (v2) πŸ“ async-http-client πŸ“ grpc-java πŸ“ Expedia Styx πŸ“ Play Framework πŸ“ reactor-netty πŸ“ vert.x πŸ“ gatling

Slide 23

Slide 23 text

blocking I/O non blocking I/O

Slide 24

Slide 24 text

JDK 1.0 socket API

Slide 25

Slide 25 text

JDK NIO

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Netty core concepts βœ… io.netty.channel.Channel A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind

Slide 28

Slide 28 text

Netty core concepts βœ… io.netty.channel.ChannelPipeline A list of ChannelHandlers which handles or intercepts inbound events and outbound operations of a Channel

Slide 29

Slide 29 text

Netty core concepts βœ… io.netty.channel.ChannelHandler Handles an I/O event or intercepts an I/O operation, and forwards it to its next handler in its ChannelPipeline

Slide 30

Slide 30 text

Netty core concepts βœ… io.netty.buffer.ByteBuf A random and sequential accessible sequence of zero or more bytes

Slide 31

Slide 31 text

High performance buffer pool Netty 4 introduces a high-performance buffer pool which is a variant of jemalloc https://netty.io/wiki/new-and-noteworthy-in-4.0.html

Slide 32

Slide 32 text

High performance buffer pool βœ… Reduced GC pressure incurred by frequent allocation and deallocation of the buffers βœ… Reduced memory bandwidth consumption incurred when creating a new buffer which inevitably has to be filled with zeroes βœ… Timely deallocation of direct buffers https://netty.io/wiki/new-and-noteworthy-in-4.0.html

Slide 33

Slide 33 text

Netty uses native code

Slide 34

Slide 34 text

Netty transports Core 🟒 JDK NIO Native transports 🟒 epoll 🟒 io_uring 🟒 kqueue

Slide 35

Slide 35 text

Netty optional libraries Native transports πŸ“ epoll transport πŸ“ io_uring transport πŸ“ kqueue transport Other πŸ“ tcnative boringssl πŸ“ brotli4j πŸ“ zstd-jni

Slide 36

Slide 36 text

Netty io_uring

Slide 37

Slide 37 text

io_uring support in Netflix Zuul βœ… https://github.com/Netflix/zuul/pull/1146

Slide 38

Slide 38 text

HTTP content compression

Slide 39

Slide 39 text

Netty compression support βœ… gzip βœ… snappy βœ… brotli βœ… zstd

Slide 40

Slide 40 text

HttpContentCompressor

Slide 41

Slide 41 text

zuul-integration-test

Slide 42

Slide 42 text

Netty pitfalls

Slide 43

Slide 43 text

Cookie class io.netty.handler.codec.http.Cookie io.netty.handler.codec.http.cookie.Cookie

Slide 44

Slide 44 text

Content compressor new HttpContentCompressor() new HttpContentCompressor((CompressorOptions[]) null)

Slide 45

Slide 45 text

Aborted (core dumped) Netty 4.1.98 + Epoll transport + Linux Netty and Java 21

Slide 46

Slide 46 text

https://netty.io/news/index.html Netty and Java 21

Slide 47

Slide 47 text

Netty resource leaks

Slide 48

Slide 48 text

https://netty.io/wiki/reference-counted-objects.html

Slide 49

Slide 49 text

https://netty.io/wiki/reference-counted-objects.html Since Netty version 4, the life cycle of certain objects are managed by their reference counts, so that Netty can return them (or their shared resources) to an object pool (or an object allocator) as soon as it is not used anymore.

Slide 50

Slide 50 text

β€œThe disadvantage of reference counting is that it is easy to leak the reference-counted objects” source: Netty wiki

Slide 51

Slide 51 text

Resource leaks are extremely difficult to debug

Slide 52

Slide 52 text

Netflix Zuul 2.x September 2017

Slide 53

Slide 53 text

Netty resource leak detector Leak Detector levels: - DISABLED - SIMPLE - ADVANCED - PARANOID

Slide 54

Slide 54 text

Best practices to avoid leaks β€œRun your unit tests and integration tests at PARANOID leak detection level” https://netty.io/wiki/reference-counted-objects.html

Slide 55

Slide 55 text

run Zuul integration test with PARANOID leak detection?

Slide 56

Slide 56 text

Netflix Zuul leak detection

Slide 57

Slide 57 text

Netflix Zuul leak detection assertZeroLeaks()

Slide 58

Slide 58 text

Netflix Zuul leak detection IntegrationTest.java

Slide 59

Slide 59 text

Netflix Zuul leak detection

Slide 60

Slide 60 text

maybe we could implement a JUnit 5 Extension class?

Slide 61

Slide 61 text

https://github.com/nettyplus/netty-leak-detector-junit-extension

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

JUnit 5 example pom.xml

Slide 64

Slide 64 text

JUnit 5 example

Slide 65

Slide 65 text

NettyLeakDetectorExtension

Slide 66

Slide 66 text

βœ… https://github.com/AsyncHttpClient/async-http-client/pull/1932

Slide 67

Slide 67 text

https://github.com/reactor/reactor-netty/pull/3064

Slide 68

Slide 68 text

Let’s talk about Apache Pinot

Slide 69

Slide 69 text

Pinot uses Netty

Slide 70

Slide 70 text

Pinot: QueryServer.java

Slide 71

Slide 71 text

Leak detection βœ… https://github.com/apache/pinot/pull/12483

Slide 72

Slide 72 text

https://github.com/apache/pinot/pull/12577 Native transports

Slide 73

Slide 73 text

Let’s talk about security

Slide 74

Slide 74 text

CVE-2023-44487 β€œHTTP 2 Rapid Reset” October 2023

Slide 75

Slide 75 text

October 2023 cloudflare.com

Slide 76

Slide 76 text

October 2023 cloudflare.com

Slide 77

Slide 77 text

Netty and HTTP 2 Rapid Reset October 10, 2023

Slide 78

Slide 78 text

Spring Boot and Netty

Slide 79

Slide 79 text

Spring Boot web servers πŸ”· JettyWebServer πŸ”· NettyWebServer πŸ”· UndertowWebServer πŸ”· TomcatWebServer

Slide 80

Slide 80 text

Spring Boot with Netty

Slide 81

Slide 81 text

Spring Boot example https://github.com/sullis/spring-boot-netty-playground

Slide 82

Slide 82 text

Learning Netty

Slide 83

Slide 83 text

πŸ“˜ published December 2015 πŸ€“ covers Netty 4.x

Slide 84

Slide 84 text

StΓ©phane Landelle @ Devoxx Belgium 2023

Slide 85

Slide 85 text

Trustin Lee @ Devoxx Belgium 2023

Slide 86

Slide 86 text

Norman Maurer @ Devoxx Belgium 2016

Slide 87

Slide 87 text

Final thoughts βœ… Netty is everywhere βœ… Netty is extensible βœ… Netty is awesome

Slide 88

Slide 88 text

Questions?

Slide 89

Slide 89 text

The End