首页 > 解决方案 > AWS vs localhost 上的可变 time.sleep(X.XX) FPS 结果

问题描述

我的异步脚本有一个主循环,在我的本地机器上每秒运行 150 000 次迭代,在 AWS 实例(Windows AMI、Python 3.7)上每秒运行大约 180 000 次迭代。

当我在这个循环中引入 time.sleep(1 / X) 时,我设法在我的本地主机上很好地限制它。例子:

while t - tzero < settings.main_loop_seconds:
    for singleobject in iterable:
        singleobject.process()     
        t= time.time()
        time.sleep(1/10000)  
        """with this I expect a maximum of 10000 iterations per second, and with the time lost to 'process' I get an actual 6500 iterations per second. As expected."""
        loopcounter += 1
        """ I reset this loopcounter to 0 from another thread (using threading.Timer)  It is used for logging the number of loops per second.

现在的问题是,在 AWS 上,相同的代码,只是在 time.sleep(1 / X) 中更改了“X”。

X = 1 # 我每秒循环 1 个

X = 10 # 我每秒循环 9 次

X = 100 #我每秒循环 64 次

X = 1000 #我每秒循环 64 次

X = 10000 #我每秒循环 64 次

X = 100000 #我每秒循环 64 次

有人可以帮助解释这种行为吗?谢谢你。

标签: python-3.xamazon-web-services

解决方案


推荐阅读