How to build an image web server?

后端 未结 4 567
青春惊慌失措
青春惊慌失措 2021-02-07 22:42

I am trying to build an web image server. It serves images to lots of clients(10 thousands+) simultaneously. (It will be a easier problem if there is fewer clients.) What is a g

4条回答
  •  半阙折子戏
    2021-02-07 23:17

    If you want to design the fastest static file webserver with lowest latency, here's how I would do it.

    1. Use an event loop to detect which sockets are ready
    2. Put those sockets in a queue
    3. Create a stack of threads to deal with sockets (1 for each core). When they finish, put them back on the stack.
    4. Assign work to threads.
    5. Cache all image files in memory.

    This is essentially what IO completion ports are minus the caching of files. This model is available in Windows and Solaris.

    http://technet.microsoft.com/en-us/sysinternals/bb963891.aspx


    (source: microsoft.com)

提交回复
热议问题