Skip to content
프로젝트

소개

Small Python examples of socket server concurrency patterns: fork, select, and more.

학습 및 교육

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
-1
in 7 days
-1
in 15 days
-1
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Simple Examples of Concurrent Server Design in Python

This repository contains minimal, educational examples of different concurrent server design patterns in Python. Each server demonstrates a classic approach used in Unix/Linux systems programming: forking, multiplexing, preforking, and more.

The goal: keep the code small and focused so you can learn the concepts without distractions.

Client

The test client works with all servers:

client.py


Server Examples

Example Technique Notes
server01.py One child per client (fork) Simple, but resource-heavy with many clients
server02.py I/O multiplexing (select) Efficient single-process model
server03.py Preforked, children call accept Demonstrates the Thundering Herd problem — multiple children wake on the same listening socket, but only one accepts. Details
server03a.py Preforked, connection distribution demo Shows how Linux distributes connections
server04.py Parent accepts, passes socket to child Avoids the Thundering Herd problem by handling accept in the parent and passing the connected socket to a child.

Quickstart

Run a server in one terminal:

python server01.py

Run the client in another:

python client.py -i localhost -p 2000 -c 5 -t 10 -b 1024

Miscellaneous Examples

Extra socket programming tricks and demos are available in the misc/ folder:


Roadmap

  • TCP Concurrent Server, One Child per Client
  • TCP Concurrent Server, I/O Multiplexing (select)
  • TCP Preforked Server, Children Call accept
  • TCP Preforked Server, Descriptor Passing
  • TCP Concurrent Server, One Thread per Client
  • TCP Concurrent Server, I/O Multiplexing (poll)
  • TCP Concurrent Server, I/O Multiplexing (epoll)
  • TCP Prethreaded Server
  • TCP_CORK socket option examples
  • Documentation for every example

Acknowledgments

  • Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition) by W. Richard Stevens, Bill Fenner, Andrew M. Rudoff
    The classic. Many techniques here are drawn from this book.

  • The Linux Programming Interface by Michael Kerrisk
    Another excellent reference.

관련 프로젝트 살펴보기

불러오는 중…