所以我有这样的代码:
amplifier = input("Enter an amount of amplifiers: ")
def threads():
for id in assetids:
x = threading.Thread(target=check_price, args=[id])
x.start()
for i in range(0, int(amplifier)):
y = threading.Thread(target=threads)
y.start()当我尝试它的时候,我捕获了网络,它使用的网络百分比/ mbps与较少的线程相同,比如100个线程与10个线程的数量相同。有人知道这是什么原因吗?另外,如果需要此信息,线程将执行for循环: for i in range(sys.maxsize**10):try:
在for循环中,它发出一个http请求,捕获html元素,然后返回并打印该元素。
发布于 2020-08-29 01:05:32
这就是所谓的收益递减定律。基本上,它说任何东西都是有极限的,你不能达到无限的速度。当您最大化使用一种资源(在您的例子中是CPU)时,您最终会遇到另一种资源的瓶颈。
在这种情况下,答案在于check_price函数正在做什么。假设你的操作系统做得不错,瓶颈可能是网络带宽、磁盘带宽或同步开销。
https://stackoverflow.com/questions/63636018
复制相似问题