四个客户端各发25个共几个
按模型,total_reqs(4, 25) 交回几?
贯穿本节的并发模型(判题机 0.25 核有 GIL、答案不靠时序,这是它的确定模型,见 spine.py):高并发服务器搭起来后要选架构、加锁护状态、连接池/队列、压测、测吞吐延迟、定位竞争。
负载测试:total_reqs(客户端, 每个)=总请求、rps(总, 秒)=每秒请求、concurrency(客户端)=并发数、completed(发出, 失败)=成功数。
def total_reqs(clients, each):
"""clients 个并发客户端各发 each 个请求,一共发多少。"""
return clients * each
def rps(total, secs):
"""平均每秒发了多少请求。"""
return total // secs
def concurrency(clients):
"""并发数就是同时打的客户端数。"""
return clients
def completed(sent, failed):
"""成功完成的请求数。"""
return sent - failed
print(total_reqs(4, 25))
全部评论