OpenSSL 3.0 performance issue: SSLContext.set_default_verify_paths / load_verify_locations about 5x slower
未關閉
還沒有人認領這個 Issue。
3.12
extension-modules
performance
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Example code in ubuntu20.04(openssl1.1) is much faster than ubuntu22.04(openssl3.x)
Not just speed, CPU occupancy ubuntu22.04(openssl3.x) is many times of ubuntu20.04(openssl1.1)
I'm not sure whether it's OpenSSL or Python adaptation problem
import socket
import ssl
import time
import certifi
hostname = 'www.python.org' # any support https hostname
times = 100
pem_where = certifi.where()
context = ssl.create_default_context()
verify_total_time = 0
for i in range(times):
with socket.create_connection((hostname, 443)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
verify_start_time = time.time()
context.load_verify_locations(pem_where)
verify_total_time += time.time() - verify_start_time
ssock.version()
print(f"total {verify_total_time:.4f}, avg {verify_total_time/times:.4f}")
in my environment with docker:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3321 root 20 0 304140 81148 12792 S 42.0 0.8 0:29.69 ipython (ubuntu22.04)
3850 root 20 0 203348 52632 11576 S 16.7 0.5 0:06.34 ipython (ubuntu20.04)
total 5.8634, avg 0.0586 (ubuntu22.04)
total 0.6753, avg 0.0068 (ubuntu20.04)
Your environment
- CPython versions tested on: 3.10.5
- Operating system and architecture: ubuntu20.04(openssl1.1) and ubuntu22.04(openssl3.0.2), build from source
- certifi==2022.6.15
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從提供的 Python 重現程式開始,在 Ubuntu 20.04/OpenSSL 1.1 和 Ubuntu 22.04/OpenSSL 3.0.2 上對 SSLContext.load_verify_locations 和 set_default_verify_paths 進行基準測試。追蹤回歸問題究竟出在 CPython 的 ssl 整合中還是 OpenSSL 中,然後確認原因,並根據報告中的耗時驗證效能改善。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- security
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100