SlideShare ist ein Scribd-Unternehmen logo
1 von 26
NOTES ON
NETTY PART 2
RICK HIGHTOWER’S
TRANSPORTS AND BUFFERS
ABOUT RICK HIGHTOWER
ABOUT RICK
• Implemented Microservices, Vert.x/Netty at massive scale
• Author of QBit, microservices lib and Boon, Json parser and utility lib
• Founder of Mammatus Technology
• Rick’s Twitter, Rick’s LinkedIn, Rick’s Blog, Rick’s Slideshare
Great book on Netty!
https://www.manning.com/books/netty-in-
action
Great talk about Netty Best Practices given at Facebook,
then Twitter University
https://goo.gl/LbXheq
http://www.infoq.com/presentations/apple-netty
Great talk about Netty at scale
PREVIOUS SLIDE DECK
PREVIOUS SLIDE DECK
• Notes on Netty Basics Part 1
• Slideshare
• http://www.slideshare.net/ric
hardhightower/notes-on-
netty-baics
• Notes on Netty Basics Part 1
• Google Slides
• https://goo.gl/aUGm2N
CHANNELS AND
TRANSPORTS
NETTY TRANSPORTS
TRANSPORTS
• OIO - old school Java networking IO lib pre NIO
• (IMO Deprecated)
• NIO - Uses Java Async API
• Epoll - Uses Linux Network libs via Java Native Interface (JNI)
• Local Transport - Async communication same JVM
• Embedded Transport - for unit testing your channel handlers
• UDS - Uses Unix Domain Sockets for same Server Interprocess
communication (IPC)
IN THE END IT IS ALL STREAMS OF OCTETS
STREAMS OF BYTES
• Old school blocking API for Java is easy to use but nothing like NIO
• Hard to switch from one to the other
• Netty provides common interface of
• blocking API (Why?),
• Java NIO (works on OS X, Windows, BSD),
• faster Linux epoll NIO,
• UDS, internal JVM, embedded for unit tests
• Same interface easy to switch between implementations
FASTER WHEN YOU DON’T HAVE TO COPY BYTES
ZERO COPY
• Only available with NIO and epoll
• Moves data from file system to network without copying buffers from
user space (your program) and kernel space (Linux, OS X, etc.)
• Works great for HTTP, FTP, anytime you can move files
HIGHLY SCALABLE IO EVENT NOTIFICATION
EPOLL
• Part of Linux Kernel since 2002 (other OS have similar event systems)
• Faster than select/poll system calls
• Java NIO uses epoll and equiv.
• Netty now has highly tuned Linux epoll implementation
• uses corking,
• send file,
• edge limit,
• much less synchronization than Java NIO
WHEN SHOULD YOU USE OIO?
OIO
• Probably never
• If doing blocking IO operations (like JDBC) maybe, but…
• You should just use your own thread pools (JDK concurrent) instead or
something like Vert.x or QBit
• Vert.x allows pools of workers called worker verticles
• QBit allows pools of service queues
• Both use Netty
TRANSPORTS
TRANSPORTS
• NIO
• TCP, UDP, SCTP, UDT (Interprocess communication)
• Epoll Linux only
• TCP, UDP
• OIO (IMO deprecated)
• TCP, UDP, SCTP, UDT
• SCTP is stream message oriented
• When to use SCTP over TCP? Who uses SCTP? 4G LTE, telephony
NETTY BUFFERS
BIG PERFORMANCE GAINS TO BE HAD
BYTEBUF
• It is all about the bytes
• Performance is reducing byte copies
• Performance is not zero-ing out buffers when not needed
• Performance is reducing the amount of direct buffer creation by
pooling buffers
BYTEBUF, BYTEBUFHOLDER
BYTE BUF API
• Easier to use API than JDK ByteBuffer
• no flip (index for read, index for write)
• Capacity is expanded on demand like ArrayList, StringBuilder
• Fluent API (method-chaining)
• Performance improvements
• Zero copy by using built-in composite buffers
• Pooling is supported
BYTEBUF, BYTEBUFHOLDER
BYTE BUF API
• read…(), skip…() operation increase read index
• write…() operation increase write index
• get…() operations to not update the indexes
• markReaderIndex(), markWriterIndex(), resetReaderIndex(), resetWriterIndex(),
writerIndex(index), readerIndex(index) to move indexes around, reset to 0, etc.
• forEachByte(predicate) to find a location in the buffer.
• If you try to read beyond what is written you get an IndexOutOfBoundException
• You can specify max capacity, defaults to MAX_VALUE on Integer
THERE ARE TWO MAIN TYPES OF BYTE BUFFERS
TWO TYPES OF BYTE BUFS
• Array backed - backed by a byte[] (byte array)
• Direct buffer
• memory gets allocated off JVM heap
• GOOD: Allows native IO calls that do not have to copy buffers to IO lib
• BAD: More expensive to allocate and release
• You need to copy data into heap to use it, can’t just ask for the array
(hasArray() == false, byteBuf.array() throws exception)
AGGREGATED VIEW OF MULTIPLE BYTEBUFS
COMPOSITE BUFFERS
• ByteBuf, CompositeByteBuf
• includes N number of on-heap (array backed) and direct byte buffers
• hasArray() only true if only backed by one on heap instance
• Use addComponent(byteBuf) to combine buffers and then no need to copy buffer
contents
• Two areas responsible for different parts of the message but the message sent back
to client
• e.g., one area creates header response, one area creates response body.
• Instead of copying buffers use CompositeByteBuf (add headers and then add
response body buf then send composite)
VIEW OR SLICE OF AN EXISTING BUFFER
DERIVED BUFFERS
• duplicate(), slice(), slice(start, stop), unmodifiableBuffer(…),
order(ByteOrder), readSlice(index)
• Return new buffer view with their own indexes and marker indexes
• Changes also change underlying buffer (use copy(), copy(start, stop) if
this is not the behavior that you want)
HOLDS A BYTE BUFFER, USED FOR BUFFER REF COUNTING
BYTE BUF HOLDER
• holds a ByteBuf
• content() returns held ByteBuf
• copy() gives a copy of the held ByteBuf
• duplicate() gives a view with unique read/write/mark indexes to the
same ByteBuf buffer data as held ByteBuf
ALLOCATING BUFFERS FROM POOLS
BYTE BUF ALLOCATORS
• ByteBufAllocator (you get it from the channel.alloc())
• Used to allocate a buffer, buffer(…), heapBuffer(…), directBuffer(…), compositeBuffer(…),
ioBuffer(…)
• May create a new buffer or use a pooled buffer
• Netty ByteBuf Allocators use Java version of jemalloc
• see talk cited in into area of this slide deck to learn more about jemalloc
• efficient pools of buffers by allowing threads to have their own cache of buffers and then fallback
to larger pool if buffer not available in thread local cache
• reduces overhead, fast, Fast, FAST
• First rule of using pools, if you allocated it, you must free it
• buffer.release()
THANKS AND BUY
NORMAN’S BOOK
NETTY IN ACTION
IDEAS FOR SLIDES
• Many ideas for slides are directly derived from Netty
in Action book by Norman et al and/or his talks on
Netty
• BUY THE BOOK Netty in Action!
• The slides are a study aid for myself so I can better
learn Netty
• I’ve worked with ByteBuffer, NIO, Vert.x, and have
often wanted to use parts of Netty on projects but
lacked the knowledge of Netty internals so used NIO
or ByteBuffer or OIO when I really wanted to use
Netty instead
PREVIOUS SLIDE DECK
PREVIOUS SLIDE DECK
• Notes on Netty Basics Part 1
• Slideshare
• http://www.slideshare.net/ric
hardhightower/notes-on-
netty-baics
• Notes on Netty Basics Part 1
• Google Slides
• https://goo.gl/aUGm2N
ABOUT RICK HIGHTOWER
ABOUT RICK
• Implemented Microservices, Vert.x/Netty at massive scale
• Author of QBit, microservices lib and Boon, Json parser and utility lib
• Founder of Mammatus Technology
• Rick’s Twitter, Rick’s LinkedIn, Rick’s Blog, Rick’s Slideshare
The end… sleepless dev.

Weitere ähnliche Inhalte

Was ist angesagt?

RabbitMQ Model and Some Example Applications
RabbitMQ Model and Some Example ApplicationsRabbitMQ Model and Some Example Applications
RabbitMQ Model and Some Example Applications
Houcheng Lin
 

Was ist angesagt? (19)

Building Netty Servers
Building Netty ServersBuilding Netty Servers
Building Netty Servers
 
Lightcycle
LightcycleLightcycle
Lightcycle
 
Using RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocolUsing RabbitMQ and Netty library to implement RPC protocol
Using RabbitMQ and Netty library to implement RPC protocol
 
Network Functions Virtualization Fundamentals
Network Functions Virtualization FundamentalsNetwork Functions Virtualization Fundamentals
Network Functions Virtualization Fundamentals
 
MidoNet deep dive
MidoNet deep diveMidoNet deep dive
MidoNet deep dive
 
Breaking down a monolith
Breaking down a monolithBreaking down a monolith
Breaking down a monolith
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
Neutron high availability open stack architecture openstack israel event 2015
Neutron high availability  open stack architecture   openstack israel event 2015Neutron high availability  open stack architecture   openstack israel event 2015
Neutron high availability open stack architecture openstack israel event 2015
 
[Draft] Fast Prototyping with DPDK and eBPF in Containernet
[Draft] Fast Prototyping with DPDK and eBPF in Containernet[Draft] Fast Prototyping with DPDK and eBPF in Containernet
[Draft] Fast Prototyping with DPDK and eBPF in Containernet
 
RabbitMQ Model and Some Example Applications
RabbitMQ Model and Some Example ApplicationsRabbitMQ Model and Some Example Applications
RabbitMQ Model and Some Example Applications
 
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
 
Coap based application for android phones
Coap based application for android phonesCoap based application for android phones
Coap based application for android phones
 
Scaling application with RabbitMQ
Scaling application with RabbitMQScaling application with RabbitMQ
Scaling application with RabbitMQ
 
Opentracing 101
Opentracing 101Opentracing 101
Opentracing 101
 
Software Defined Networking: The OpenDaylight Project
Software Defined Networking: The OpenDaylight ProjectSoftware Defined Networking: The OpenDaylight Project
Software Defined Networking: The OpenDaylight Project
 
NATS for Modern Messaging and Microservices
NATS for Modern Messaging and MicroservicesNATS for Modern Messaging and Microservices
NATS for Modern Messaging and Microservices
 
MPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI ForumMPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI Forum
 
Understanding and Extending Prometheus AlertManager
Understanding and Extending Prometheus AlertManagerUnderstanding and Extending Prometheus AlertManager
Understanding and Extending Prometheus AlertManager
 
Streams API (Web Engines Hackfest 2015)
Streams API (Web Engines Hackfest 2015)Streams API (Web Engines Hackfest 2015)
Streams API (Web Engines Hackfest 2015)
 

Andere mochten auch

Introduction of netty
Introduction of nettyIntroduction of netty
Introduction of netty
Bing Luo
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
Daniel Bimschas
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
Allan Huang
 
Processing edges on apache giraph
Processing edges on apache giraphProcessing edges on apache giraph
Processing edges on apache giraph
DataWorks Summit
 
Apache AVRO (Boston HUG, Jan 19, 2010)
Apache AVRO (Boston HUG, Jan 19, 2010)Apache AVRO (Boston HUG, Jan 19, 2010)
Apache AVRO (Boston HUG, Jan 19, 2010)
Cloudera, Inc.
 

Andere mochten auch (20)

Netty - a pragmatic introduction
Netty - a pragmatic introductionNetty - a pragmatic introduction
Netty - a pragmatic introduction
 
Netty 시작하기 (2)
Netty 시작하기 (2)Netty 시작하기 (2)
Netty 시작하기 (2)
 
Introduction of netty
Introduction of nettyIntroduction of netty
Introduction of netty
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 
Netty Cookbook - Table of contents
Netty Cookbook - Table of contentsNetty Cookbook - Table of contents
Netty Cookbook - Table of contents
 
Asynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with NettyAsynchronous, Event-driven Network Application Development with Netty
Asynchronous, Event-driven Network Application Development with Netty
 
Get started with netty
Get started with nettyGet started with netty
Get started with netty
 
Netty from the trenches
Netty from the trenchesNetty from the trenches
Netty from the trenches
 
Netty 4-based RPC System Development
Netty 4-based RPC System DevelopmentNetty 4-based RPC System Development
Netty 4-based RPC System Development
 
Using SCTP with Scamper and Netty
Using SCTP with Scamper and NettyUsing SCTP with Scamper and Netty
Using SCTP with Scamper and Netty
 
Ambry : Linkedin's Scalable Geo-Distributed Object Store
Ambry : Linkedin's Scalable Geo-Distributed Object StoreAmbry : Linkedin's Scalable Geo-Distributed Object Store
Ambry : Linkedin's Scalable Geo-Distributed Object Store
 
Netty
NettyNetty
Netty
 
Netty Cookbook - Chapter 1
Netty Cookbook - Chapter 1Netty Cookbook - Chapter 1
Netty Cookbook - Chapter 1
 
Processing edges on apache giraph
Processing edges on apache giraphProcessing edges on apache giraph
Processing edges on apache giraph
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
Apache AVRO (Boston HUG, Jan 19, 2010)
Apache AVRO (Boston HUG, Jan 19, 2010)Apache AVRO (Boston HUG, Jan 19, 2010)
Apache AVRO (Boston HUG, Jan 19, 2010)
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread pools
 
【Potatotips #26】Replace EventBus with RxJava/RxAndroid
【Potatotips #26】Replace EventBus with RxJava/RxAndroid【Potatotips #26】Replace EventBus with RxJava/RxAndroid
【Potatotips #26】Replace EventBus with RxJava/RxAndroid
 
Java SE 8 技術手冊第 15 章 - 通用API
Java SE 8 技術手冊第 15 章 - 通用APIJava SE 8 技術手冊第 15 章 - 通用API
Java SE 8 技術手冊第 15 章 - 通用API
 

Ähnlich wie Netty Notes Part 2 - Transports and Buffers

yocto_scale_handout-with-notes
yocto_scale_handout-with-notesyocto_scale_handout-with-notes
yocto_scale_handout-with-notes
Steve Arnold
 
The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...
The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...
The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...
mfrancis
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
LibX2.0-Code4Lib-2009AsPresented
LibX2.0-Code4Lib-2009AsPresentedLibX2.0-Code4Lib-2009AsPresented
LibX2.0-Code4Lib-2009AsPresented
tutorialsruby
 

Ähnlich wie Netty Notes Part 2 - Transports and Buffers (20)

Kube 101
Kube 101Kube 101
Kube 101
 
Demystifying kubernetes
Demystifying kubernetesDemystifying kubernetes
Demystifying kubernetes
 
Brief Introduction To Kubernetes
Brief Introduction To KubernetesBrief Introduction To Kubernetes
Brief Introduction To Kubernetes
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Cloud Infrastructures Slide Set 7 - Docker - Neo4j | anynines
Cloud Infrastructures Slide Set 7 - Docker - Neo4j | anyninesCloud Infrastructures Slide Set 7 - Docker - Neo4j | anynines
Cloud Infrastructures Slide Set 7 - Docker - Neo4j | anynines
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
 
yocto_scale_handout-with-notes
yocto_scale_handout-with-notesyocto_scale_handout-with-notes
yocto_scale_handout-with-notes
 
Building an Event Bus at Scale
Building an Event Bus at ScaleBuilding an Event Bus at Scale
Building an Event Bus at Scale
 
Latest (storage IO) patterns for cloud-native applications
Latest (storage IO) patterns for cloud-native applications Latest (storage IO) patterns for cloud-native applications
Latest (storage IO) patterns for cloud-native applications
 
Introduction to TokuDB v7.5 and Read Free Replication
Introduction to TokuDB v7.5 and Read Free ReplicationIntroduction to TokuDB v7.5 and Read Free Replication
Introduction to TokuDB v7.5 and Read Free Replication
 
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
 
The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...
The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...
The Bundle Dilemma - Richard S. Hall, Researcher, Laboratoire d’Informatique ...
 
OpenStack: Toward a More Resilient Cloud
OpenStack: Toward a More Resilient CloudOpenStack: Toward a More Resilient Cloud
OpenStack: Toward a More Resilient Cloud
 
DoxLon | Life with kube, containers and microservices
DoxLon | Life with kube, containers and microservicesDoxLon | Life with kube, containers and microservices
DoxLon | Life with kube, containers and microservices
 
Handling I/O in Java
Handling I/O in JavaHandling I/O in Java
Handling I/O in Java
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
EhTrace -- RoP Hooks
EhTrace -- RoP HooksEhTrace -- RoP Hooks
EhTrace -- RoP Hooks
 
Alluxio - Scalable Filesystem Metadata Services
Alluxio - Scalable Filesystem Metadata ServicesAlluxio - Scalable Filesystem Metadata Services
Alluxio - Scalable Filesystem Metadata Services
 
gcdtmp
gcdtmpgcdtmp
gcdtmp
 
LibX2.0-Code4Lib-2009AsPresented
LibX2.0-Code4Lib-2009AsPresentedLibX2.0-Code4Lib-2009AsPresented
LibX2.0-Code4Lib-2009AsPresented
 

Mehr von Rick Hightower

Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)
Rick Hightower
 
Consul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive ProgrammingConsul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive Programming
Rick Hightower
 
The Java Microservice Library
The Java Microservice LibraryThe Java Microservice Library
The Java Microservice Library
Rick Hightower
 

Mehr von Rick Hightower (17)

JParse Fast JSON Parser
JParse Fast JSON ParserJParse Fast JSON Parser
JParse Fast JSON Parser
 
Service Mesh Talk for CTO Forum
Service Mesh Talk for CTO ForumService Mesh Talk for CTO Forum
Service Mesh Talk for CTO Forum
 
Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)Service Mesh CTO Forum (Draft 3)
Service Mesh CTO Forum (Draft 3)
 
Accelerate Delivery: Business Case for Agile DevOps, CI/CD and Microservices
Accelerate Delivery: Business Case for Agile DevOps, CI/CD and MicroservicesAccelerate Delivery: Business Case for Agile DevOps, CI/CD and Microservices
Accelerate Delivery: Business Case for Agile DevOps, CI/CD and Microservices
 
Accelerate Delivery: Business case for Agile DevOps, CI/CD and Microservices
Accelerate Delivery: Business case for Agile DevOps, CI/CD and MicroservicesAccelerate Delivery: Business case for Agile DevOps, CI/CD and Microservices
Accelerate Delivery: Business case for Agile DevOps, CI/CD and Microservices
 
Accelerate DevOps/Microservices and Kubernetes
Accelerate DevOps/Microservices and KubernetesAccelerate DevOps/Microservices and Kubernetes
Accelerate DevOps/Microservices and Kubernetes
 
Accelerate using DevOps and CI/CD.
Accelerate using DevOps and CI/CD.Accelerate using DevOps and CI/CD.
Accelerate using DevOps and CI/CD.
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
 
High-Speed Reactive Microservices - trials and tribulations
High-Speed Reactive Microservices - trials and tribulationsHigh-Speed Reactive Microservices - trials and tribulations
High-Speed Reactive Microservices - trials and tribulations
 
High-Speed Reactive Microservices
High-Speed Reactive MicroservicesHigh-Speed Reactive Microservices
High-Speed Reactive Microservices
 
WebSocket MicroService vs. REST Microservice
WebSocket MicroService vs. REST MicroserviceWebSocket MicroService vs. REST Microservice
WebSocket MicroService vs. REST Microservice
 
Consul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive ProgrammingConsul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive Programming
 
The Java Microservice Library
The Java Microservice LibraryThe Java Microservice Library
The Java Microservice Library
 
Java JSON Benchmark
Java JSON BenchmarkJava JSON Benchmark
Java JSON Benchmark
 
MongoDB quickstart for Java, PHP, and Python developers
MongoDB quickstart for Java, PHP, and Python developersMongoDB quickstart for Java, PHP, and Python developers
MongoDB quickstart for Java, PHP, and Python developers
 
Mongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP DevelopersMongo DB for Java, Python and PHP Developers
Mongo DB for Java, Python and PHP Developers
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Netty Notes Part 2 - Transports and Buffers

  • 1. NOTES ON NETTY PART 2 RICK HIGHTOWER’S TRANSPORTS AND BUFFERS
  • 2. ABOUT RICK HIGHTOWER ABOUT RICK • Implemented Microservices, Vert.x/Netty at massive scale • Author of QBit, microservices lib and Boon, Json parser and utility lib • Founder of Mammatus Technology • Rick’s Twitter, Rick’s LinkedIn, Rick’s Blog, Rick’s Slideshare
  • 3. Great book on Netty! https://www.manning.com/books/netty-in- action
  • 4. Great talk about Netty Best Practices given at Facebook, then Twitter University https://goo.gl/LbXheq
  • 6. PREVIOUS SLIDE DECK PREVIOUS SLIDE DECK • Notes on Netty Basics Part 1 • Slideshare • http://www.slideshare.net/ric hardhightower/notes-on- netty-baics • Notes on Netty Basics Part 1 • Google Slides • https://goo.gl/aUGm2N
  • 8. NETTY TRANSPORTS TRANSPORTS • OIO - old school Java networking IO lib pre NIO • (IMO Deprecated) • NIO - Uses Java Async API • Epoll - Uses Linux Network libs via Java Native Interface (JNI) • Local Transport - Async communication same JVM • Embedded Transport - for unit testing your channel handlers • UDS - Uses Unix Domain Sockets for same Server Interprocess communication (IPC)
  • 9. IN THE END IT IS ALL STREAMS OF OCTETS STREAMS OF BYTES • Old school blocking API for Java is easy to use but nothing like NIO • Hard to switch from one to the other • Netty provides common interface of • blocking API (Why?), • Java NIO (works on OS X, Windows, BSD), • faster Linux epoll NIO, • UDS, internal JVM, embedded for unit tests • Same interface easy to switch between implementations
  • 10. FASTER WHEN YOU DON’T HAVE TO COPY BYTES ZERO COPY • Only available with NIO and epoll • Moves data from file system to network without copying buffers from user space (your program) and kernel space (Linux, OS X, etc.) • Works great for HTTP, FTP, anytime you can move files
  • 11. HIGHLY SCALABLE IO EVENT NOTIFICATION EPOLL • Part of Linux Kernel since 2002 (other OS have similar event systems) • Faster than select/poll system calls • Java NIO uses epoll and equiv. • Netty now has highly tuned Linux epoll implementation • uses corking, • send file, • edge limit, • much less synchronization than Java NIO
  • 12. WHEN SHOULD YOU USE OIO? OIO • Probably never • If doing blocking IO operations (like JDBC) maybe, but… • You should just use your own thread pools (JDK concurrent) instead or something like Vert.x or QBit • Vert.x allows pools of workers called worker verticles • QBit allows pools of service queues • Both use Netty
  • 13. TRANSPORTS TRANSPORTS • NIO • TCP, UDP, SCTP, UDT (Interprocess communication) • Epoll Linux only • TCP, UDP • OIO (IMO deprecated) • TCP, UDP, SCTP, UDT • SCTP is stream message oriented • When to use SCTP over TCP? Who uses SCTP? 4G LTE, telephony
  • 15. BIG PERFORMANCE GAINS TO BE HAD BYTEBUF • It is all about the bytes • Performance is reducing byte copies • Performance is not zero-ing out buffers when not needed • Performance is reducing the amount of direct buffer creation by pooling buffers
  • 16. BYTEBUF, BYTEBUFHOLDER BYTE BUF API • Easier to use API than JDK ByteBuffer • no flip (index for read, index for write) • Capacity is expanded on demand like ArrayList, StringBuilder • Fluent API (method-chaining) • Performance improvements • Zero copy by using built-in composite buffers • Pooling is supported
  • 17. BYTEBUF, BYTEBUFHOLDER BYTE BUF API • read…(), skip…() operation increase read index • write…() operation increase write index • get…() operations to not update the indexes • markReaderIndex(), markWriterIndex(), resetReaderIndex(), resetWriterIndex(), writerIndex(index), readerIndex(index) to move indexes around, reset to 0, etc. • forEachByte(predicate) to find a location in the buffer. • If you try to read beyond what is written you get an IndexOutOfBoundException • You can specify max capacity, defaults to MAX_VALUE on Integer
  • 18. THERE ARE TWO MAIN TYPES OF BYTE BUFFERS TWO TYPES OF BYTE BUFS • Array backed - backed by a byte[] (byte array) • Direct buffer • memory gets allocated off JVM heap • GOOD: Allows native IO calls that do not have to copy buffers to IO lib • BAD: More expensive to allocate and release • You need to copy data into heap to use it, can’t just ask for the array (hasArray() == false, byteBuf.array() throws exception)
  • 19. AGGREGATED VIEW OF MULTIPLE BYTEBUFS COMPOSITE BUFFERS • ByteBuf, CompositeByteBuf • includes N number of on-heap (array backed) and direct byte buffers • hasArray() only true if only backed by one on heap instance • Use addComponent(byteBuf) to combine buffers and then no need to copy buffer contents • Two areas responsible for different parts of the message but the message sent back to client • e.g., one area creates header response, one area creates response body. • Instead of copying buffers use CompositeByteBuf (add headers and then add response body buf then send composite)
  • 20. VIEW OR SLICE OF AN EXISTING BUFFER DERIVED BUFFERS • duplicate(), slice(), slice(start, stop), unmodifiableBuffer(…), order(ByteOrder), readSlice(index) • Return new buffer view with their own indexes and marker indexes • Changes also change underlying buffer (use copy(), copy(start, stop) if this is not the behavior that you want)
  • 21. HOLDS A BYTE BUFFER, USED FOR BUFFER REF COUNTING BYTE BUF HOLDER • holds a ByteBuf • content() returns held ByteBuf • copy() gives a copy of the held ByteBuf • duplicate() gives a view with unique read/write/mark indexes to the same ByteBuf buffer data as held ByteBuf
  • 22. ALLOCATING BUFFERS FROM POOLS BYTE BUF ALLOCATORS • ByteBufAllocator (you get it from the channel.alloc()) • Used to allocate a buffer, buffer(…), heapBuffer(…), directBuffer(…), compositeBuffer(…), ioBuffer(…) • May create a new buffer or use a pooled buffer • Netty ByteBuf Allocators use Java version of jemalloc • see talk cited in into area of this slide deck to learn more about jemalloc • efficient pools of buffers by allowing threads to have their own cache of buffers and then fallback to larger pool if buffer not available in thread local cache • reduces overhead, fast, Fast, FAST • First rule of using pools, if you allocated it, you must free it • buffer.release()
  • 24. NETTY IN ACTION IDEAS FOR SLIDES • Many ideas for slides are directly derived from Netty in Action book by Norman et al and/or his talks on Netty • BUY THE BOOK Netty in Action! • The slides are a study aid for myself so I can better learn Netty • I’ve worked with ByteBuffer, NIO, Vert.x, and have often wanted to use parts of Netty on projects but lacked the knowledge of Netty internals so used NIO or ByteBuffer or OIO when I really wanted to use Netty instead
  • 25. PREVIOUS SLIDE DECK PREVIOUS SLIDE DECK • Notes on Netty Basics Part 1 • Slideshare • http://www.slideshare.net/ric hardhightower/notes-on- netty-baics • Notes on Netty Basics Part 1 • Google Slides • https://goo.gl/aUGm2N
  • 26. ABOUT RICK HIGHTOWER ABOUT RICK • Implemented Microservices, Vert.x/Netty at massive scale • Author of QBit, microservices lib and Boon, Json parser and utility lib • Founder of Mammatus Technology • Rick’s Twitter, Rick’s LinkedIn, Rick’s Blog, Rick’s Slideshare The end… sleepless dev.