【发布时间】:2021-03-21 17:38:04
【问题描述】:
我正在尝试找出使用streamz 处理流数据的正确方法。我的流数据是使用websocket-client 加载的,之后我这样做:
# open a stream and push updates into the stream
stream = Stream()
# establish a connection
ws = create_connection("ws://localhost:8765")
# get continuous updates
from tornado import gen
from tornado.ioloop import IOLoop
async def f():
while True:
await gen.sleep(0.001)
data = ws.recv()
stream.emit(data)
IOLoop.current().add_callback(f)
虽然这可行,但我发现我的流无法跟上流数据的速度(因此我在流中看到的数据比流数据落后几秒钟,这既是高容量又是高频率的数据)。我尝试将gen.sleep(0.001) 设置为较小的值(删除它会完全停止 jupyter 实验室),但问题仍然存在。
这是使用 websocket 连接 streamz 和流数据的正确方法吗?
【问题讨论】: