-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.3] Fix instrumentation refresh rate #21
Comments
chatting with @jjderooy we think that geeksforgeeks.org/python-os-pipe-method might be a good solution |
I did some testing, turns out that it is not a file bottleneck. In my experiment, When calling I think the real bottleneck is either websocket related, or plotting related on the UI frontend. I don't know much about either of them, but we can at least test the websocket throughput by just logging the data to a file rather than trying to display it. That isn't to say that we shouldn't use pipes as Kris suggested, just that to solve our bottleneck we need to look elsewhere and that should be the priority before refining the file reading spaghetti. generator.pyimport json
import random
import time
with open('instrumentation_data.txt', 'a') as file:
for i in range(0,10000):
data = {f"PT_{i:02}": random.randint(0, 10000) for i in range(1, 11)}
json.dump(data, file)
file.write('\n')
with open('tmp.txt', 'w') as tmp:
json.dump(data, tmp)
tmp.write('\n!')
time.sleep(0.001) reader.pyimport json
import time
# read_data.txt should be a copy of instrumentation_data.txt
with open ('read_data.txt', 'w') as file:
last_line = ""
while True:
with open('tmp.txt', 'r') as tmp:
lines = tmp.readlines()
if len(lines) > 1 and lines[0] != last_line:
last_line = lines[0]
file.write(lines[0]) |
@klemie could you test to see if it is a websocket, file io or async bottleneck by commenting out different parts of this code in async def __instrumentation_handler(self, websocket):
while True:
with open('instrumentation/tmp.txt', 'r') as file:
lines = file.readlines()
if len(lines) > 1:
await websocket.send(json.dumps({
"identifier": "INSTRUMENTATION",
"data": json.loads(lines[0])
}))
await asyncio.sleep(0.1)
These aren't perfect tests but maybe they'll give enough idea of where the slowness is coming from. |
Description
Currently we have a bottle neck in our infrastructure. We are taking advantage of files like an
OS
to get info from the labjack to the websocket. We've tried async python and it made thing much more worse and complicated. So we simplified to file reading and writing. Unfortunately we seem to have a deadlock issue, we try to read from the file at a rate higher than it can decode/write to it.This ticket goes into one of two solutions:
Acceptance Criteria
QA Notes
Linked issues
The text was updated successfully, but these errors were encountered: