Going on with this series of brief demos about how to embed Wasmer binaries into Python modules via python-ext-wasmer
(see previous episodes 1 and 2).
I wondered what it would look like a Web application that leverages Wasm binaries; let's use Flask micro-framework!
We start the usual way, using the previously compiled Rust functions. For this experiment we pick:
- The two versions of Fibonacci, one as Python function, the other as Wasm-compiled Rust;
- The two versions for a static computation of Convex Hull.
This time we wrap the pre-compiled binaries into a Flask app and serve them through two endpoints:
As you can see, the loading of the binaries is practically at no-cost in terms of service performance as it is done at app creation. This allows to load as much binaries as we need to perform the processing via the endpoints. It could possibly be a good solution for a RPC API that accepts arbitrary parameters.
Let's try to run it:
[UPDATED]
platform linux -- Python 3.6.8, pytest-4.4.1, py-1.8.0, pluggy-0.9.0
rootdir: /home/mec-is/rustcode/wasm-python-101
collected 4 items
pywasm/examples/flask_basic/tests.py 2019-08-18 16:17.29 Time it func=fibo_wasm time=0.07568788528442383
.2019-08-18 16:17.35 Time it func=fibo_py time=0.06508588790893555
.2019-08-18 16:17.41 Time it func=convexhull_wasm time=0.10294783115386963
.2019-08-18 16:17.48 Time it func=convexhull_py time=0.4820021390914917
Not bad for a first run!
Top comments (0)