Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Tornado (webserver with WebSocket)

Questions and comments specific to a particular plugin should go here.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Tornado (webserver with WebSocket)

Post by krambriw »

I think...if you are streaming video over your network, you should be more worried about that load
m19brandon
Experienced User
Posts: 177
Joined: Mon Feb 03, 2014 10:36 pm

Re: Tornado (webserver with WebSocket)

Post by m19brandon »

I like the idea of using EG as a proxy for everything. Allows the backend work to stay the same well the UI can change over time.

This is my Family Remote Remote. I have mine setup as a webpage on iphones and android tables with everything working great but for one timeout bug due to iphones not fully supporting HTML5.
https://drive.google.com/file/d/0B8D4iq ... sp=sharing

I do not find your site slow either but did see a 4mb image.

Take at look my js\script.js code. I touch Pako's example, removed everything that was not needed for my site and rewrote the websocket functions a little. I believe this made my site a little faster.

What plugin are your using for zwave?
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Tornado (webserver with WebSocket)

Post by krambriw »

So in my attempts to improve the reliability of websocket connections, I dived into the Tornado plugin.

I have as described in the Corning Corner researched a lot in how to handle websocket connections and in line with that work made some improvements of the plugin (at least it has helped very much in my environment).

The following has been modified:
- introduced retries in BroadcastMessage function
- added, where missing, a short sleep in all while loops to free CPU
- added support for handling an incoming 'Ping' event responding with a
'Pong' response

I have noticed that sometimes the first message does not receive the client (for whatever reason) but a second attempt worked. The change is so far made only in the BroadcastMessage function, up to 5 retries are made before the client connection is considered dead. This has proved that the connection in most cases survives and continuous to work.

In all while loops it is healthy to have a short sleep (0.05 seconds) to release the CPU. the sleep has been added where missing. There is no noticeable decrease in performance but the CPU load never goes high.

I added support to respond with 'Pong' to 'Ping' messages. According recommendations, a message should be sent at least every 45 seconds to keep the connection. The 'Pong' response can be evaluated by the client to perform any action on missing response, e.g. close and reconnect the websocket connection.

To use the 'Ping' feature, you just send a message from the web browser containing the word 'Ping'. The 'Pong' response received back in the web browser will typically look like this:

Code: Select all

["Pong", ["192.168.10.2", 23901]]

The updated version is attached below
__init__.py
(124.89 KiB) Downloaded 196 times
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Tornado (webserver with WebSocket)

Post by Pako »

Dear Walter!
Like I already wrote in another topic, I very much appreciate your admirable work.
Thank you for the significant improvement of this plugin!

Best regards,
Luboš
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Tornado (webserver with WebSocket)

Post by krambriw »

Here is just an interesting part from my log demonstrating how it now works. I cleared the log in EG around nine last night and since then we can clearly see two things
- there are messages that does not arrive to clients at first attempt but they do all arrive on the first retry
- connections are sometimes lost but they are now re-established within 2 seconds

Worth to mention is that
- all clients (tablets) and EG server are all wireless connected to my network
- EG server has a fixed ip, tablets are running android and have reserved ip's (192.168.10.6 and 192.168.10.5) in the DHCP server
- 192.168.10.6 is running UC browser and 192.168.10.5 Chrome
- I estimate that the EG server in my system is broadcasting maybe 50-80 messages per minute

Code: Select all


2015-02-20 21:08:00           ---> Welcome to EventGhost <---
2015-02-20 22:52:50           HTTP.WsClientDisconnected [('192.168.10.6', 36841)]
2015-02-20 22:52:50           HTTP.WsClientConnected [('192.168.10.6', 57166)]
2015-02-20 23:36:33           New attempt: 0 ('192.168.10.6', 57166)
2015-02-21 00:26:43           New attempt: 0 ('192.168.10.6', 57166)
2015-02-21 00:48:47           HTTP.WsClientDisconnected [('192.168.10.6', 57166)]
2015-02-21 00:48:48           HTTP.WsClientConnected [('192.168.10.6', 42089)]
2015-02-21 01:14:44           New attempt: 0 ('192.168.10.6', 42089)
2015-02-21 01:47:42           HTTP.WsClientDisconnected [('192.168.10.6', 42089)]
2015-02-21 01:47:42           HTTP.WsClientConnected [('192.168.10.6', 56292)]
2015-02-21 04:16:46           New attempt: 0 ('192.168.10.6', 56292)
2015-02-21 04:26:36           HTTP.WsClientDisconnected [('192.168.10.6', 56292)]
2015-02-21 04:26:37           HTTP.WsClientConnected [('192.168.10.6', 46143)]
2015-02-21 05:10:31           New attempt: 0 ('192.168.10.6', 46143)
2015-02-21 08:35:29           New attempt: 0 ('192.168.10.6', 46143)
2015-02-21 09:27:21           HTTP.WsClientDisconnected [('192.168.10.5', 40813)]
2015-02-21 09:27:22           HTTP.WsClientConnected [('192.168.10.5', 40830)]
2015-02-21 09:29:13           New attempt: 0 ('192.168.10.5', 40830)
2015-02-21 09:33:31           New attempt: 0 ('192.168.10.6', 46143)
2015-02-21 09:34:14           New attempt: 0 ('192.168.10.6', 46143)
2015-02-21 09:40:30           HTTP.WsClientDisconnected [('192.168.10.5', 40830)]
2015-02-21 09:40:31           HTTP.WsClientConnected [('192.168.10.5', 40833)]
2015-02-21 09:41:24           New attempt: 0 ('192.168.10.5', 40833)
2015-02-21 09:43:24           HTTP.WsClientDisconnected [('192.168.10.6', 46143)]
2015-02-21 09:43:25           HTTP.WsClientConnected [('192.168.10.6', 43918)]
2015-02-21 09:48:34           New attempt: 0 ('192.168.10.5', 40833)
2015-02-21 10:03:37           New attempt: 0 ('192.168.10.5', 40833)
2015-02-21 10:06:42           New attempt: 0 ('192.168.10.6', 43918)
2015-02-21 10:17:57           New attempt: 0 ('192.168.10.5', 40833)
2015-02-21 10:18:40           HTTP.WsClientDisconnected [('192.168.10.6', 43918)]
2015-02-21 10:18:41           HTTP.WsClientConnected [('192.168.10.6', 57844)]
2015-02-21 10:20:49           New attempt: 0 ('192.168.10.6', 57844)
2015-02-21 10:21:32           New attempt: 0 ('192.168.10.6', 57844)
2015-02-21 10:28:42           New attempt: 0 ('192.168.10.6', 57844)
2015-02-21 10:30:51           New attempt: 0 ('192.168.10.5', 40833)
2015-02-21 10:44:17           New attempt: 0 ('192.168.10.6', 57844)
2015-02-21 10:45:54           New attempt: 0 ('192.168.10.5', 40833)
2015-02-21 11:01:40           New attempt: 0 ('192.168.10.6', 57844)
2015-02-21 11:09:33           HTTP.WsClientDisconnected [('192.168.10.5', 40833)]
2015-02-21 11:09:34           HTTP.WsClientConnected [('192.168.10.5', 40844)]
2015-02-21 11:10:16           New attempt: 0 ('192.168.10.6', 57844)
2015-02-21 11:27:28           New attempt: 0 ('192.168.10.6', 57844)
2015-02-21 11:34:29           HTTP.WsClientDisconnected [('192.168.10.6', 57844)]
2015-02-21 11:34:31           HTTP.WsClientConnected [('192.168.10.6', 48226)]
2015-02-21 11:36:13           New attempt: 0 ('192.168.10.5', 40844)
2015-02-21 11:40:22           New attempt: 0 ('192.168.10.6', 48226)
2015-02-21 11:43:14           New attempt: 0 ('192.168.10.5', 40844)
2015-02-21 11:48:04           HTTP.WsClientDisconnected [('192.168.10.5', 40844)]
2015-02-21 11:48:05           HTTP.WsClientConnected [('192.168.10.5', 40849)]
2015-02-21 11:48:58           New attempt: 0 ('192.168.10.6', 48226)

Post Reply