Speed & Optimization - duxiaoyao/pdp GitHub Wiki
Python code is VERY SLOW and VERY POOR MULTI-CORE CONCURRENCY
- dynamically-typed
- GIL (Global Interpreter Lock) per process
Python+uvloop:
- faster than Golang on a single core but does not scale on two cores (单核networking很强,不输Go,但多核不行)
- Its performance drastically decreases when running python code to process the request
Python with Cython scales on multiple cores and runs faster than Go
Cython + wrapper of C libraries
可以通过Cython等C化缓解: statically compiled to C, release GIL for multicore concurrancy
Use Rust, Go, or C/C++: low latency, high concurrency, multi-core execution within single user-space shared memory
Back to the Metal:
- Rust to replace C/C++
- Go to replace Java
对Web和微服务(IO密集、无状态)来说,通过利用asyncio和起多进程,Python代码运行性能的问题不是问题。
References: