I have a simple json REST server on my LAN. I need to let clients on the LAN POST/PUT and GET camera live stream seamlessly over http. I tried two simple approaches:
Method1 (without Session):
while (frame):
dict_obj = image_to_dict_converter(frame)
json_obj = str(json.loads(dict_obj))
requests.put(url, headers=headers, data = json.dumps({'data': str(json.loads(json_obj))}), timeout = 0.1)
Method2 (with Session):
ses = requests.Session()
while (frame):
dict_obj = image_to_dict_converter(frame)
json_obj = str(json.loads(dict_obj))
ses.put(url, headers=headers, data = json.dumps({'data': str(json.loads(json_obj))}),timeout = 0.1)
Same methods are used withGET. I tried both on Apache2 and Nginx, and since Nginx resulted in better performance, my REST server is now linked to Nginx. I am able to stream and visualize the video on a client-server-client topology. Method2 works smoothly (~0 sec latency) and at high fps, it however freezes once a while for 6 seconds (probably Session is limited to a number of calls). Method1 works reliably, however, at low fps and with 0.5 sec constant latency in frames.
My question is how can I technically improve the methods for realtime services? (Can anyone provide an example?) Also, how can I tune Nginx to handle such service in terms of speed and number of requests?
UPDATE:
I noticed that web server (Nginx) is interrupting the stream, it has no issues when requests are redirected directly to the port number my REST listens to (localhost:8888) instead of localhost (managed by Nginx)