Netty Official Introduction#
Netty is an asynchronous event-driven network application framework
for rapid development of maintainable high-performance protocol servers & clients.
Netty is an asynchronous event-driven network application framework.
Used for the rapid development of maintainable high-performance protocol servers and clients.
Netty is a NIO client-server framework that enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket servers.
'Quick and easy' doesn't mean that a resulting application will suffer from maintainability or performance issues. Netty has been carefully designed with the experiences gained from the implementation of a lot of protocols such as FTP, SMTP, HTTP, and various binary and text-based legacy protocols. As a result, Netty has succeeded in finding a way to achieve ease of development, performance, stability, and flexibility without compromise.
Netty is a NIO client-server framework that enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket servers.
"Quick and easy" does not mean that the resulting application will suffer from maintainability or performance issues. Netty's design has been carefully designed, drawing from the experience of implementing many protocols such as FTP, SMTP, HTTP, and various binary and text-based legacy protocols. Therefore, Netty has successfully found a way to achieve ease of development, performance, stability, and flexibility without compromise.
Why Learn Netty?#
- Netty is already the industry standard for network communication programming and is widely used in the communication field and the underlying technology of many other middleware technologies.
- It has a wide range of applications
- Gaming industry
- Communication underlying many frameworks, solving inter-process communication.
Spring WebFlux, storm, rocketMQ, dubbo, etc., are the core of distributed systems communication.
What are the problems with traditional IO?#
- Multi-threaded network programming
1.1 Thread creation overhead
Traditional IO communication uses multiple threads, and each client connection in the server program will open a thread. Opening and closing a thread both have overhead.
2.2 High CPU usage
Assuming that 1000 threads exist simultaneously, after each thread's time slice is used up, there will be overhead in context switching (context switching can be understood as the operating system saving the place where the time slice is used up so that it can continue executing from that place the next time it gets a time slice).
2.3 High memory usage, it is not possible to create threads indefinitely
Hardware resources are precious, and a thread occupies approximately 1MB in Java. A large number of creations will lead to insufficient memory.
- Thread pool network programming
The pooling concept solves the problem of creating threads indefinitely and can take advantage of the multi-core CPU in the code.
However, a new problem arises. Suppose there are 100 threads coming in, but the thread pool can only handle 10 requests. The remaining 90 threads can only wait in the queue for thread processing, causing a blocking problem.
The example above is still an ideal situation. Suppose the incoming 10 threads are blocked for some reason, then the 10 threads in the thread pool must wait for these 10 requests to be processed before they can handle the remaining 90 requests. The blocking problem becomes very serious, resulting in the waste of limited resources.
Conclusion#
Why use Netty? Because Netty uses NIO at the underlying level, it solves the above communication problems.
The End!!!