⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 the c10k problem.mht

📁 It s time for web servers to handle ten thousand clients simultaneously, don t you think? After all,
💻 MHT
📖 第 1 页 / 共 5 页
字号:
From: <óé Microsoft Internet Explorer 5 ±£′?>
Subject: The C10K problem
Date: Wed, 20 Jun 2007 14:35:17 +0800
MIME-Version: 1.0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.kegel.com/c10k.html
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>The C10K problem</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.3020" name=3DGENERATOR></HEAD>
<BODY>
<H1><A name=3Dtop>The C10K problem</A></H1><FONT color=3Dred>[<A=20
href=3D"http://www.lwn.net/">Help save the best Linux news source on the =
web --=20
subscribe to Linux Weekly News!</A>]</FONT>=20
<P>It's time for web servers to handle ten thousand clients =
simultaneously,=20
don't you think? After all, the web is a big place now.=20
<P>And computers are big, too. You can buy a 1000MHz machine with 2 =
gigabytes of=20
RAM and an 1000Mbit/sec Ethernet card for $1200 or so. Let's see - at =
20000=20
clients, that's 50KHz, 100Kbytes, and 50Kbits/sec per client. It =
shouldn't take=20
any more horsepower than that to take four kilobytes from the disk and =
send them=20
to the network once a second for each of twenty thousand clients. (That =
works=20
out to $0.08 per client, by the way. Those $100/client licensing fees =
some=20
operating systems charge are starting to look a little heavy!) So =
hardware is no=20
longer the bottleneck.=20
<P>In 1999 one of the busiest ftp sites, cdrom.com, actually handled =
10000=20
clients simultaneously through a Gigabit Ethernet pipe. As of 2001, that =
same=20
speed is now <A =
href=3D"http://www.senteco.com/telecom/ethernet.htm">being offered=20
by several ISPs</A>, who expect it to become increasingly popular with =
large=20
business customers.=20
<P>And the thin client model of computing appears to be coming back in =
style --=20
this time with the server out on the Internet, serving thousands of =
clients.=20
<P>With that in mind, here are a few notes on how to configure operating =
systems=20
and write code to support thousands of clients. The discussion centers =
around=20
Unix-like operating systems, as that's my personal area of interest, but =
Windows=20
is also covered a bit.=20
<H2>Contents</H2>
<UL>
  <LI><A href=3D"http://www.kegel.com/c10k.html#top">The C10K =
problem</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#related">Related =
Sites</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#books">Book to Read =
First</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#frameworks">I/O =
frameworks</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#strategies">I/O =
Strategies</A>=20
  <OL>
    <LI><A href=3D"http://www.kegel.com/c10k.html#nb">Serve many clients =
with each=20
    thread, and use nonblocking I/O and <B>level-triggered</B> readiness =

    notification</A>=20
    <UL>
      <LI><A href=3D"http://www.kegel.com/c10k.html#nb.select">The =
traditional=20
      select()</A>=20
      <LI><A href=3D"http://www.kegel.com/c10k.html#nb.poll">The =
traditional=20
      poll()</A>=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#nb./dev/poll">/dev/poll</A>=20
      (Solaris 2.7+)=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#nb.kqueue">kqueue</A>=20
      (FreeBSD, NetBSD) </LI></UL>
    <LI><A href=3D"http://www.kegel.com/c10k.html#nb.edge">Serve many =
clients with=20
    each thread, and use nonblocking I/O and readiness <B>change</B>=20
    notification</A>=20
    <UL>
      <LI><A href=3D"http://www.kegel.com/c10k.html#nb.epoll">epoll</A> =
(Linux=20
      2.6+)=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#nb.kevent">Polyakov's=20
      kevent</A> (Linux 2.6+)=20
      <LI><A href=3D"http://www.kegel.com/c10k.html#nb.newni">Drepper's =
New=20
      Network Interface</A> (proposal for Linux 2.6+)=20
      <LI><A href=3D"http://www.kegel.com/c10k.html#nb.sigio">Realtime =
Signals</A>=20
      (Linux 2.4+)=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#nb.sigfd">Signal-per-fd</A>=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#nb.kqueue">kqueue</A>=20
      (FreeBSD, NetBSD) </LI></UL>
    <LI><A href=3D"http://www.kegel.com/c10k.html#aio">Serve many =
clients with=20
    each thread, and use asynchronous I/O and completion =
notification</A>=20
    <LI><A href=3D"http://www.kegel.com/c10k.html#threaded">Serve one =
client with=20
    each server thread</A>=20
    <UL>
      <LI><A=20
      =
href=3D"http://www.kegel.com/c10k.html#threads.linuxthreads">LinuxThreads=
</A>=20
      (Linux 2.0+)=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#threads.ngpt">NGPT</A> (Linux=20
      2.4+)=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#threads.nptl">NPTL</A> (Linux=20
      2.6, Red Hat 9)=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#threads.freebsd">FreeBSD=20
      threading support</A>=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#threads.netbsd">NetBSD=20
      threading support</A>=20
      <LI><A =
href=3D"http://www.kegel.com/c10k.html#threads.solaris">Solaris=20
      threading support</A>=20
      <LI><A href=3D"http://www.kegel.com/c10k.html#threads.java">Java =
threading=20
      support in JDK 1.3.x and earlier</A>=20
      <LI><A href=3D"http://www.kegel.com/c10k.html#1:1">Note: 1:1 =
threading vs.=20
      M:N threading</A> </LI></UL>
    <LI><A href=3D"http://www.kegel.com/c10k.html#kio">Build the server =
code into=20
    the kernel</A> </LI></OL>
  <LI><A href=3D"http://www.kegel.com/c10k.html#comments">Comments</A>=20
  <LI><A =
href=3D"http://www.kegel.com/c10k.html#limits.filehandles">Limits on =
open=20
  filehandles</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#limits.threads">Limits =
on=20
  threads</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#java">Java issues</A> =
[Updated 27=20
  May 2001]=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#tips">Other tips</A>=20
  <UL>
    <LI><A =
href=3D"http://www.kegel.com/c10k.html#zerocopy">Zero-Copy</A>=20
    <LI><A href=3D"http://www.kegel.com/c10k.html#sendfile">The =
sendfile() system=20
    call can implement zero-copy networking.</A>=20
    <LI><A href=3D"http://www.kegel.com/c10k.html#writev">Avoid small =
frames by=20
    using writev (or TCP_CORK)</A>=20
    <LI><A href=3D"http://www.kegel.com/c10k.html#nativethreads">Some =
programs can=20
    benefit from using non-Posix threads.</A>=20
    <LI><A href=3D"http://www.kegel.com/c10k.html#caching">Caching your =
own data=20
    can sometimes be a win.</A> </LI></UL>
  <LI><A href=3D"http://www.kegel.com/c10k.html#limits.other">Other =
limits</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#kernel">Kernel =
Issues</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#benchmarking">Measuring =
Server=20
  Performance</A>=20
  <LI><A href=3D"http://www.kegel.com/c10k.html#examples">Examples</A>=20
  <UL>
    <LI><A =
href=3D"http://www.kegel.com/c10k.html#examples.nb.select">Interesting=20
    select()-based servers</A>=20
    <LI><A=20
    =
href=3D"http://www.kegel.com/c10k.html#examples.nb./dev/poll">Interesting=
=20
    /dev/poll-based servers</A>=20
    <LI><A =
href=3D"http://www.kegel.com/c10k.html#examples.nb.kqueue">Interesting=20
    kqueue()-based servers</A>=20
    <LI><A =
href=3D"http://www.kegel.com/c10k.html#examples.nb.sigio">Interesting=20
    realtime signal-based servers</A>=20
    <LI><A =
href=3D"http://www.kegel.com/c10k.html#examples.threaded">Interesting=20
    thread-based servers</A>=20
    <LI><A =
href=3D"http://www.kegel.com/c10k.html#examples.kio">Interesting=20
    in-kernel servers</A> </LI></UL>
  <LI><A href=3D"http://www.kegel.com/c10k.html#links">Other interesting =
links</A>=20
  </LI></UL>
<P>
<H2><A name=3Drelated>Related Sites</A></H2>In October 2003, Felix von =
Leitner put=20
together an excellent <A href=3D"http://bulk.fefe.de/scalability/">web =
page</A>=20
and <A =
href=3D"http://bulk.fefe.de/scalable-networking.pdf">presentation</A> =
about=20
network scalability, complete with benchmarks comparing various =
networking=20
system calls and operating systems. One of his observations is that the =
2.6=20
Linux kernel really does beat the 2.4 kernel, but there are many, many =
good=20
graphs that will give the OS developers food for thought for some time. =
(See=20
also the <A=20
href=3D"http://developers.slashdot.org/developers/03/10/19/0130256.shtml?=
tid=3D106&amp;tid=3D130&amp;tid=3D185&amp;tid=3D190">Slashdot</A>=20
comments; it'll be interesting to see whether anyone does followup =
benchmarks=20
improving on Felix's results.)=20
<H2><A name=3Dbooks>Book to Read First</A></H2>
<P>If you haven't read it already, go out and get a copy of <A=20
href=3D"http://www.amazon.com/exec/obidos/ASIN/013490012X/">Unix Network =

Programming : Networking Apis: Sockets and Xti (Volume 1)</A> by the =
late W.=20
Richard Stevens. It describes many of the I/O strategies and pitfalls =
related to=20
writing high-performance servers. It even talks about the <A=20
href=3D"http://www.citi.umich.edu/projects/linux-scalability/reports/acce=
pt.html">'thundering=20
herd'</A> problem. And while you're at it, go read <A=20
href=3D"http://pl.atyp.us/content/tech/servers.html">Jeff Darcy's notes =
on=20
high-performance server design</A>.=20
<P>(Another book which might be more helpful for those who are *using* =
rather=20
than *writing* a web server is <A=20
href=3D"http://www.amazon.com/gp/product/0596102356">Building Scalable =
Web=20
Sites</A> by Cal Henderson.)=20
<H3><A name=3Dframeworks>I/O frameworks</A></H3>
<P>Prepackaged libraries are available that abstract some of the =
techniques=20
presented below, insulating your code from the operating system and =
making it=20
more portable.=20
<UL>
  <LI><A href=3D"http://www.cs.wustl.edu/~schmidt/ACE.html">ACE</A>, a =
heavyweight=20
  C++ I/O framework, contains object-oriented implementations of some of =
these=20
  I/O strategies and many other useful things. In particular, his =
Reactor is an=20
  OO way of doing nonblocking I/O, and Proactor is an OO way of doing=20
  asynchronous I/O.=20
  <LI><A href=3D"http://asio.sf.net/">ASIO</A> is an C++ I/O framework =
which is=20
  becoming part of the Boost library. It's like ACE updated for the STL =
era.=20
  <LI><A href=3D"http://monkey.org/~provos/libevent">libevent</A> is a =
lightweight=20
  C I/O framework by Niels Provos. It supports kqueue and select, and =
soon will=20
  support poll and epoll. It's level-triggered only, I think, which has =
both=20
  good and bad sides. Niels has <A=20
  href=3D"http://monkey.org/~provos/libevent/libevent-benchmark.jpg">a =
nice graph=20
  of time to handle one event</A> as a function of the number of =
connections. It=20
  shows kqueue and sys_epoll as clear winners.=20
  <LI>My own attempts at lightweight frameworks (sadly, not kept up to =
date):=20
  <UL>
    <LI><A =
href=3D"http://www.kegel.com/dkftpbench/Poller_bench.html">Poller</A>=20
    is a lightweight C++ I/O framework that implements a level-triggered =

    readiness API using whatever underlying readiness API you want =
(poll,=20
    select, /dev/poll, kqueue, or sigio). It's useful for <A=20
    =
href=3D"http://www.kegel.com/dkftpbench/Poller_bench.html">benchmarks =
that=20
    compare the performance of the various APIs.</A> This document links =
to=20
    Poller subclasses below to illustrate how each of the readiness APIs =
can be=20
    used.=20
    <LI><A href=3D"http://www.kegel.com/rn/">rn</A> is a lightweight C =
I/O=20
    framework that was my second try after Poller. It's lgpl (so it's =
easier to=20
    use in commercial apps) and C (so it's easier to use in non-C++ =
apps). It=20
    was used in some commercial products. </LI></UL>
  <LI>Matt Welsh wrote <A=20
  href=3D"http://www.cs.berkeley.edu/~mdw/papers/events.pdf">a paper</A> =
in April=20
  2000 about how to balance the use of worker thread and event-driven =
techniques=20
  when building scalable servers. The paper describes part of his =
Sandstorm I/O=20
  framework.=20
  <LI><A=20
  =
href=3D"http://svn.sourceforge.net/viewcvs.cgi/*checkout*/int64/scale/rea=
dme.txt">Cory=20
  Nelson's Scale! library</A> - an async socket, file, and pipe I/O =
library for=20
  Windows </LI></UL>
<H2><A name=3Dstrategies>I/O Strategies</A></H2>Designers of networking =
software=20
have many options. Here are a few:=20

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -