ws: tiny asynchronous webserver framework without uasyncio

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
bitninja
Posts: 165
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: ws: tiny asynchronous webserver framework without uasyncio

Post by bitninja » Fri Nov 17, 2017 7:07 pm

jacob019 wrote:
Fri Nov 17, 2017 6:21 pm
I would really like to figure out why you are not getting the same results:
1. Are you on the ESP8266?
2. Is the device connected to the network in STA mode?
Yes, I am using a Wemos D1 Mini and I am connecting to my local wifi in STA mode.

jacob019
Posts: 13
Joined: Tue Oct 03, 2017 6:14 pm

Re: ws: tiny asynchronous webserver framework without uasyncio

Post by jacob019 » Fri Nov 17, 2017 7:08 pm

@bitninja
802.11n? What version of MicroPython? Do you have anything else running at startup (besides webrepl)?

@pythoncoder
I prepared a minimal test case:
http://jacobstoner.com/test.py
It isn't quite as minimal as I would like, but the discrepancy goes away in the simplest of examples where there aren't any function calls in the loop. The script serves ~100kB of spaces as soon as the port is opened, alternately between identical functions where one uses native code and the other does not. The time spent waiting on select.poll is printed each time.

Here's a shell command to make the requests:
for ((n=0;n<10;n++)); do sh -c 'nc 10.0.0.172 9999 > /dev/zero'; done

The timed output is printed on the REPL:
Not Native: 12669ms
Native: 3646ms
Not Native: 15057ms
Native: 3725ms
Not Native: 11584ms
Native: 3922ms
Not Native: 11080ms
Native: 4232ms
Not Native: 11839ms
Native: 3939ms

Here we see a 2X-3X difference, but for real work loads like file serving the difference is a more dramatic 5X-7X. This is just the time spent waiting on select.poll, other differences in execution speed between native and non-native code should not be reflected here. I'll open an issue on the micropython github repo when I get a chance.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ws: tiny asynchronous webserver framework without uasyncio

Post by pythoncoder » Sat Nov 18, 2017 9:22 am

jacob019 wrote:
Fri Nov 17, 2017 7:08 pm
...I'll open an issue on the micropython github repo when I get a chance...
That would be very useful.
jacob019 wrote:
Fri Nov 17, 2017 7:08 pm
......the discrepancy goes away in the simplest of examples where there aren't any function calls in the loop...
Worth pointing out when you raise the issue; also the point about the resultant heavy performance hit when using uasyncio.
Peter Hinch
Index to my micropython libraries.

jacob019
Posts: 13
Joined: Tue Oct 03, 2017 6:14 pm

Re: ws: tiny asynchronous webserver framework without uasyncio

Post by jacob019 » Tue Nov 21, 2017 10:00 pm

https://github.com/micropython/micropython/issues/3451
The overwhelming majority of commits to micropython are from dpgeorge, the creator, and from pfalcon. There are well over 300 open issues. These guys are stretched thin.

Edit: Good news, Damien just submitted a patch that improves the ESP8266 TCP upload performance by >10X and eliminates the performance difference. I will be using asyncio henceforth.

Post Reply