项目作者: f034d21a

项目描述 :
Python Coroutine Pool
高级语言: Python
项目地址: git://github.com/f034d21a/read_the_docs.git
创建时间: 2017-05-07T12:28:08Z
项目社区:https://github.com/f034d21a/read_the_docs

开源协议:

下载


1. Requirements

  1. git clone <repository>
  2. cd <repository_directory>
  3. python3 -m venv env # Python >= 3.5.0
  4. env/bin/pip install -r requirements.txt

2. AsyncIOPool

Coroutine pool, it’s more lightweight and faster than thread and process

2.1. Usage:

  1. pool = AsyncIOPool(loop, workers, timeout, default)
  2. for arg, ret in pool.map(coroutine, sequence):
  3. pass

2.2. Benchmark:

  1. # usage
  2. test_aio_pool.py --sleep SLEEP --sample SAMPLE --workers WORKERS [--log-level LOG_LEVEL]
  3. # examples
  4. env/bin/python test_aio_pool.py --sleep 0.1 --sample 100 --workers 10
  5. env/bin/python test_aio_pool.py --sleep 1 --sample 1000 --workers 100
  6. env/bin/python test_aio_pool.py --sleep 10 --sample 10000 --workers 1000
  7. # output
  8. ------------------------------ sleep: 0.1, sample: 100, workers: 10 ------------------------------
  9. coroutine map benchmark: 1.006 seconds
  10. thread map benchmark: 1.354 seconds
  11. process map benchmark: 1.274 seconds
  12. ------------------------------ sleep: 1, sample: 1000, workers: 100 ------------------------------
  13. coroutine map benchmark: 10.023 seconds
  14. thread map benchmark: 12.135 seconds
  15. process map benchmark: 12.393 seconds
  16. ------------------------------ sleep: 10, sample: 10000, workers: 1000 ------------------------------
  17. coroutine map benchmark: 100.160 seconds
  18. thread map benchmark: 129.090 seconds
  19. process map benchmark: BlockingIOError: [Errno 35] Resource temporarily unavailable

3. Downloader

3.1. Usage:

  1. downloader = Downloader(url, path, name, timeout, bytes_per_time, max_connections)
  2. downloader.start()

3.2. Command line:

  1. downloader.py --url URL [--path PATH] [--name NAME] [--timeout TIMEOUT] [--bytes-per-time BYTES_PER_TIME] [--max-connections MAX_CONNECTIONS]
  2. # example
  3. env/bin/python downloader.py --url http://mirrors.hust.edu.cn/apache/hadoop/common/hadoop-2.8.0/hadoop-2.8.0.tar.gz --bytes-per-time 1048576
  4. # output
  5. 4% (18 of 411) |# | Elapsed Time: 0:00:08 ETA: 0:03:21

4. ReadTheDocsDownloader

4.1. Usage:

  1. read_the_docs = ReadTheDocsDownloader(project, version, path, timeout, bytes_per_time, max_connections)
  2. read_the_docs.start()

4.2. Command line:

  1. read_the_docs.py --project PROJECT [--version VERSION] [--path PATH] [--timeout TIMEOUT] [--bytes-per-time BYTES_PER_TIME] [--max-connections MAX_CONNECTIONS]
  2. # example
  3. env/bin/python read_the_docs.py --project aiohttp --bytes-per-time 102400
  4. # output
  5. 49% (82 of 166) |####################################### | Elapsed Time: 0:00:06 ETA: 0:00:08