kqueue

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 on July 2000,[1][2] also supported in NetBSD, OpenBSD, DragonFly BSD, and macOS. Kqueue was originally authored in 2000 by Jonathan Lemon,[1][2] then involved with the FreeBSD Core Team. Kqueue makes it possible for software like nginx to solve the c10k problem.[3][4]

Kqueue provides efficient input and output event pipelines between the kernel and userland. Thus, it is possible to modify event filters as well as receive pending events while using only a single system call to kevent(2) per main event loop iteration. This contrasts with older traditional polling system calls such as poll(2) and select(2) which are less efficient, especially when polling for events on a large number of file descriptors.

Kqueue not only handles file descriptor events but is also used for various other notifications such as file modification monitoring, signals, asynchronous I/O events (AIO), child process state change monitoring and timers which support nanosecond resolution.

Some other operating systems which traditionally only supported select(2) and poll(2) also currently provide more efficient polling alternatives, such as epoll on Linux and I/O completion ports on Windows and Solaris.

See also[edit]

OS-independent libraries with support for kqueue:

Kqueue equivalent for other platforms:

  • on Solaris, Windows and AIX: I/O completion ports
  • on Linux:
    • epoll system call has similar but not identical semantics. epoll notifies when a file descriptor is ready to perform an I/O operation, whereas kqueue & IOCP notify when a requested operation has completed.
    • inotify is a Linux kernel subsystem that notices changes to the filesystem and reports those to applications.

libkqueue is a user space implementation of kqueue(2), which translates calls to an operating system's native backend event mechanism.[5]

References[edit]

  1. ^ a b Jonathan Lemon (2000). "kqueue, kevent — kernel event notification mechanism". BSD Cross Reference. FreeBSD, OpenBSD, NetBSD, DragonFly BSD. Lay summary.
  2. ^ a b Jonathan Lemon (2001-05-01). Kqueue: A generic and scalable event notification facility (PDF). Proceedings of the FREENIX Track: 2001 USENIX Annual Technical Conference. USENIX (published June 25–30, 2001). Lay summary.CS1 maint: date format (link)
  3. ^ "Connection processing methods". nginx.org.
  4. ^ Andrew Alexeev (2012). "§14. nginx". In Amy Brown; Greg Wilson (eds.). The Architecture of Open Source Applications, Volume II: Structure, Scale and a Few More Fearless Hacks. Lulu.com. ISBN 9781105571817.
  5. ^ libkqueue on GitHub

External links[edit]