Please format your code using </>
icon as explained in this guide. It will make your post more readable.
I edited your question.
Just a comment here. Don't send bulk requests every 5ms. It does not make sense.
Use something like 5s, even more.
Not sure it would help.
The other part of the code looks ok.