카테고리 없음
Does Netty use Servlet?
홍호나
2025. 6. 10. 18:42
Does Netty use Servlet?
Netty is a highly performant, non-blocking I/O framework for building network applications. Unlike Jetty, it does not follow the Java Servlet model but instead operates on event loops.
- Netty :
- 비동기 이벤트 기반의 네트워크 애플리케이션을 개발하기 위한 프레임워크 비동기? - 처리될 때까지 기다리는 것이 아니라 요청은 요청대로, 응답은 응답대로 따로 하는 것 → 독립적으로 돌아가는 행위
- ex) Ajax
- 주로 고성능, 확장 가능한 네트워크 서버를 개발하는데 사용 → 처리를 기다리지 않고 바로 다른 작업을 진행할 수 있으니까
- 보통 웹, 게임, 채팅, 프록시 서버 등과 같은 네트워크 기반의 어플리케이션을 개발하는데 활용 → 언제 요청이 들어올지 모르는데, 요청이 들어오면 즉각처리해줘야하는 것들 중 성능이 요구되는 서비스에 사용된다.
- 비동기 이벤트 기반의 네트워크 애플리케이션을 개발하기 위한 프레임워크 비동기? - 처리될 때까지 기다리는 것이 아니라 요청은 요청대로, 응답은 응답대로 따로 하는 것 → 독립적으로 돌아가는 행위
- Tomcat :
- 서블릿(Servlet) 컨테이너로서, JSP와 Servlet 기술을 사용하여 Java 웹 애플리케이션을 실행하는데 사용
- 동시성 처리보다는 싱글 스레드 형식( 단일 요청→단일 응답 처리 )에 적합
What is event loop in Netty?
The event loop in Netty is a crucial component of its asynchronous, event-driven architecture. It's essentially a single-threaded loop that handles I/O operations for one or more channels. Here's a breakdown:
Core Functionality
-
Single-Threaded:Each EventLoop runs on its own thread, ensuring that events for a specific channel are processed sequentially, eliminating the need for complex synchronization mechanisms.
-
Event Processing:The EventLoop continuously monitors for I/O events such as accepting new connections, reading data from sockets, and writing data to sockets.
-
Task Queue:It manages a queue of tasks, executing them one by one in the order they were submitted. This includes user-defined tasks and callbacks.
-
Channel Lifecycle:The EventLoop is responsible for the lifecycle of channels, including registration, deregistration, and closing.
How it Works
-
Event Detection:The EventLoop waits for I/O events to occur on the channels it manages.
-
Event Dispatch:When an event occurs, the EventLoop dispatches it to the appropriate handler.
-
Task Execution:The handler processes the event and may submit additional tasks to the EventLoop's queue.
-
Looping:The EventLoop continues to process events and execute tasks in a loop, ensuring that all operations are handled efficiently and asynchronously.
Key Benefits
-
Non-Blocking I/O:The EventLoop enables non-blocking I/O operations, allowing Netty to handle a large number of concurrent connections with a minimal number of threads.
-
Performance:By avoiding thread context switching, the EventLoop improves performance and reduces overhead.
-
Simplicity:It simplifies the management of concurrent operations, making it easier to build highly scalable and responsive applications.
In summary, the EventLoop is the heart of Netty's asynchronous processing model, providing a single-threaded, event-driven approach to handling I/O operations and tasks.