|
||||||
|
| Abstract | Introduction
| Event Notification with
poll() | POSIX Real Time Signals
| Using RealTime
Signals for Network I/O | | Performance
Benefits | RealTime
Signal Problems and Fixes | Signal
Queue Overflow |
| Signals on Closed Socket | Lost Events Before Enabling RealTime Signals | Skipping Events | Performance Comparision | |Conclusion | References | About ViSolve.com | |
||||||
Abstract |
POSIX RealTime signals are potentially a better alternative to polling for scalable network I/O. RealTime signals provide a fast, scalable mechanism for signaling network events. However, they also introduce race-condition problems which application writers must deal with. We describe solutions for using RealTime signals properly. Finally we compare the performance of a cache server using both polling and RealTime signals. | |||||
Introduction |
Internet servers today must handle thousands of concurrent client connections. One of the main bottlenecks for these servers is event notification for socket I/O. In the ideal scenario, the server's response time should scale linearly with the number of active socket connections.However, the
traditional POSIX RealTime signals provide a better alternative to polling for socket I/O. Furthermore, the main obstacle to using RealTime signals, signal queue overflow, has been solved by the one-signal-per-fd patch [4]. This paper is organized as follows: Section 2 presents the poll() interface and reveals its scalability problems. Section 3 introduces RealTime signals and why it performs better. In Section 4 we describe difficulties in using RealTime signals, and fixes for dealing with these problems. Section 5 compares the performance of the Squid cache server using both polling and RealTime signals. We present our conclusions in Section 6. |
|||||
Event notification with poll() |
Event notification with poll()Poll() interfaceThe traditional way to check for socket events on a large number of clients is by using the poll() or select() system calls. Figure 1 summarizes the poll() interface from the Linux man page.
The application
passes an array of pollfd containing the sockets and the
events to check for. The timeout value specifies how long the process
should
wait for an event to occur on any of the sockets. When the poll()
function
returns, it stores the actual events ready on each socket in the
revents
field of each pollfd.Scalability ProblemsThe poll() system
call performs poorly when the application passes an array
with thousands of sockets. The poll() call has scalability problems for
the
following reasons: [1]
Related WorkSeveral new
interfaces have been proposed to address the performance problems
of poll() and select() for network I/O Banga and Mogul [1] propose the
system
calls
declare_interest() and get_next_event()
to
register a socket for event notification and to retrieve events. The /dev/poll
interface improves upon poll()
by reducing
copying between user and kernel. However, /dev/poll
still must poll
all open sockets at the kernel level, and therefore also has
scalability
problems [2]. A new interface called kqueue[3] has been implemented on
the
FreeBSD operating system. Kqueue was designed to eliminate the
performance
problems of polling and avoid the difficulties found in RealTime
signals. But,
there is currently no implementation for Linux yet. Our main focus is
on
RealTime signals because it is readily available for Linux. |
|||||
POSIX RealTime Signals |
POSIX RealTime SignalsPOSIX RealTime Signals are a general mechanism for asynchronous event delivery. For servers, RealTime signals can be used to notify socket events to the application. RealTime signals potentially offer better performance for network I/O than polling.Comparison with standard signalsPOSIX RealTime signals differ from standard UNIX signals in the following two ways:
|
|||||
Using RealTime signals for network I/O |
User applications perform the following steps to use RealTime signals for socket event notification. First, the user enables RealTime signals on the socket file descriptor. Figure 3 lists the flags that must be set to enable RealTime signals. Once the flags in Figure 3 are set, RealTime signals are enabled for that socket, until it is closed. Whenever an I/O event occurs on the socket, a RealTime signal will be added to the signal queue.
Figure 4 shows how the application retrieves socket events from the signal queue. The application uses the sigwaitinfo() or sigtimedwait() system calls. The sigwaitinfo() call takes as arguments the signal set to wait for, and a siginfo structure to store the signal event. It blocks until a signal in the signal set is received in the signal queue. The socket event is stored in the siginfo_t structure, as shown in Figure 2.
|
|||||
Performance benefits |
RealTime signals perform better than polling because they scale linearly with the number of active sockets; poll() scales linearly with the number of total sockets being serviced. Figure 5 illustrates the main design differences that benefit RealTime signals:
|
|||||
RealTime signal problems and fixes |
We believe that RealTime signals have not achieved widespread use because of difficulties in use for application writers. To investigate the complexity of using RealTime signals in a server, we modified the Squid Web Cache Server [7] to use RealTime signals. Unfortunately, we encountered several problems that make RealTime signals difficult to use. We discuss both kernel and user level fixes to work around these problems. |
|||||
Signal Queue Overflow |
The number of RealTime signals sent to a process can grow infinitely. A single socket can send multiple I/O events, resulting in multiple signals in the queue. When the RealTime signal queue overflows, the application must perform complicated steps to recover. The application receives a SIGIO signal when the queue overflows. To resolve the signal overflow, the application must disable RealTime signals on all sockets, and remove all signals from the signal queue. Then, to retrieve the lost socket events, the application must poll all the sockets. As expected, handling signal queue overflow increases the complexity of the application, and degrades the performance under high load [2]. Queue overflow has been a major obstacle in using RealTime signals.A solution to avoid
signal queue overflow is to allow only one event per
socket file descriptor in the signal queue. If multiple events occur on
the same
socket, the event flags for the /* Allow only one signal per socket fd */ |
|||||
Signals on closed socket |
When a socket is
closed, the corresponding RealTime signals in the signal
queue are not removed. This forces the application to deal with expired
events
that no longer correspond to an open socket. A simple workaround is to struct file
contains a pointer to the
corresponding siginfo_t in the signal queue.
When the socket
closes, the signal can be either removed from the queue, or the events
flags can
be reset to 0, indicating that no event occurred. |
|||||
Lost events before enabling RealTime signals |
Socket events can be lost before RealTime signals are enabled. When a new client socket is accepted, data can arrive on the socket before RealTime signals are enabled on the socket. Although data is available on the socket, no signal will be sent to the application, so the I/O event is lost. The solution we
implemented to work around this problem is to poll every
client socket immediately after enabling RealTime signals on that
socket. This
extra |
|||||
Skipping events |
RealTime signals
are only sent once, so the application cannot skip or defer
events. When using This problem cannot be solved efficiently by the kernel. If the kernel constantly resends skipped events, the application will essentially be polling the socket, which leads to performance degradation. Ultimately, the user level code must be rewritten so that socket events are never ignored. For example, in our Squid implementation, we had to abandon the bandwidth limiting features (called delay pools) because RealTime signals do not allow skipping socket events. |
|||||
Performance Comparison |
Test setupTo test the performance benefits of RealTime signals, we modified the Squid Web Cache server [7] to use RealTime signals for network I/O instead ofpoll(). The tests were performed on an HP
Netserver lp1000r with an
866Mhz CPU, 512 MB memory, and two 8 GB SCSI hard disks. The machines
ran Red
Hat Linux 7.1 with the Luban one-sig-perfd patch. To compare
performance, we
used the Web Polygraph benchmark [8] for caching proxies. |
|||||
Conclusion |
This paper has discussed the limitations ofpoll()
for highly
concurrent network I/O. We introduced RealTime signals as a better
alternative
to poll. RealTime signals provide efficient event notification. The
performance
of RealTime signals depends only on the number of active sockets, and
not number
of total clients. The one-sig-perfd patch eliminates signal queue
overflow,
overcoming a major hurdle to using RealTime signals. Performance tests
with
Squid have demonstrated that porting server applications to RealTime
signals
dramatically improves throughput of the server. |
|||||
References |
[1] G. Banga and J. C. Mogul. Scalable kernel performance for Internet servers under realistic loads. In Proceedings of the USENIX Annual Technical Conference, June 1998 [2] A. Chandra and D. Mosberger. Scalability of Linux Event Dispatch Mechanisms. HP Labs Technical Report, December 2000 [3] J. Lemon. Kqueue: A generic and scalable event notification facility. In Proceedings of the USENIX Annual Technical Conference, June 2001 [4] N. Provos and C. Lever. Scalable Network I/O in Linux. In Proceedings of the USENIX Annual Technical Conference, June 2000 [5] Squid Cache Server. http://www.squid-cache.org/ [6] Web Polygraph benchmark. http://www.web-polygraph.org/ |
|||||
|
About ViSolve.com ViSolve is an international corporation that provides technical services, for Internet based systems, for clients around the globe. ViSolve is in the business of providing software solutions since 1995. We have experience of executing several major projects and we are now completely focused on leading Internet technologies, Testing QA and support. We are committed to the Open source movement and in the same lines we provide free support for products like Linux, Apache and Squid to the user community. |
||||||
| Document Version : 1.0 | Created On : 28-01-02 | Updated On : 30-05-06 |
||||||