Websockify: Reconsider numpy usage and recommendation

Created on 19 Apr 2013  ·  2Comments  ·  Source: novnc/websockify

Currently, websockify/websocket.py will give a warning if "numpy" is not available:

WARNING: no 'numpy' module, HyBi protocol is slower or disabled

This is somewhat confusing. First of all, HyBi is definitely not "disabled". And is it really slower? I've done some tests with noVNC, and even when playing Youtube videos with a high frame rate, the process using websocket.py doesn't consume much CPU at all; it rarely shows up in the "top" listing at all. So I'm wondering, has any real measurements been done on this? I've done some Googling and failed to find anything (except problems with numpy...). IMHO, unless we can measure that numpy makes a substantial difference, I think it would be better and more clean to only require standard Python functionality.

question

Most helpful comment

The "slower or disabled" part is because there are 4 different python modules that are optional and checked using the same code at the top of websocket.py. For example, if the ssl module is not found, then TLS/wss is disabled. I just pushed a change that will make this clearer.

Numpy is definitely faster. Using the tests/latency.py + tests/latency.html test I get the following results (with 10ms send delay and just running on localhost):

Packet size 2000 bytes:

  • 0.8ms avg roundtrip latency with numpy
  • 1.6ms avg roundtrip latency without numpy

Packet size 20000 bytes:

  • 2.5ms avg roundtrip latency with numpy
  • 9.2ms avg roundtrip latency without numpy

Packet size 100000 bytes:

  • 6.3ms avg roundtrip latency with numpy
  • 40.1ms avg rountrip latency without numpy

In addition, with 100kb packet sizes, no only is the latency more 6 times higher without numpy, but the server starts to get behind and the client has to back off repeatedly during the test.

Note that numpy really only affects client->server data unmasking, so for uses like noVNC it will be basically irrelevant. However, websockify is not just for noVNC, so in the case where the client is sending a lot of data to server, numpy provides significant performance improvement.

All 2 comments

The "slower or disabled" part is because there are 4 different python modules that are optional and checked using the same code at the top of websocket.py. For example, if the ssl module is not found, then TLS/wss is disabled. I just pushed a change that will make this clearer.

Numpy is definitely faster. Using the tests/latency.py + tests/latency.html test I get the following results (with 10ms send delay and just running on localhost):

Packet size 2000 bytes:

  • 0.8ms avg roundtrip latency with numpy
  • 1.6ms avg roundtrip latency without numpy

Packet size 20000 bytes:

  • 2.5ms avg roundtrip latency with numpy
  • 9.2ms avg roundtrip latency without numpy

Packet size 100000 bytes:

  • 6.3ms avg roundtrip latency with numpy
  • 40.1ms avg rountrip latency without numpy

In addition, with 100kb packet sizes, no only is the latency more 6 times higher without numpy, but the server starts to get behind and the client has to back off repeatedly during the test.

Note that numpy really only affects client->server data unmasking, so for uses like noVNC it will be basically irrelevant. However, websockify is not just for noVNC, so in the case where the client is sending a lot of data to server, numpy provides significant performance improvement.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

doriwal picture doriwal  ·  26Comments

blite picture blite  ·  3Comments

hansent picture hansent  ·  3Comments

ispmarin picture ispmarin  ·  3Comments

gw0 picture gw0  ·  3Comments