[HN Gopher] WebVM: Server-less x86 virtual machines in the browser
___________________________________________________________________
WebVM: Server-less x86 virtual machines in the browser
Author : AshleysBrain
Score : 127 points
Date : 2022-02-01 19:01 UTC (3 hours ago)
(HTM) web link (leaningtech.com)
(TXT) w3m dump (leaningtech.com)
| bkyan wrote:
| How do you move files into or out of this VM?
| williamstein wrote:
| The JIT compilation to WebAssembly they are doing with WebVM is
| pretty cool!
|
| I didn't see any benchmarks on the linked to page. I tried their
| sample Fibonacci program, but up to 100000 and ONLY timing actual
| execution (using the time Python module) to not include startup
| time, and WebVM only took 6.7 times as long as native for me.
| That's very impressive.
|
| There's a similar open source project called
| https://copy.sh/v86/. Using their arch Linux image with the exact
| same Fibonacci benchmark, it take 44 times as long as native.
| syrusakbary wrote:
| Thanks for the benchmarks! I was curious about timing.
|
| Python is also a bit tricky because it does things with
| pointers that I believe are hard to optimize (or maybe not, who
| knows!). Have you tried other languages/programs?
| benou wrote:
| I timed a very simple loop in C: "for (volatile int i=0; i<N;
| i++);" (handful of arithmetic, compare and branch instructions)
| with N=1e9 and it was 70% the speed of native which looks
| really good. I'd love to see LINPACK now :)
| syrusakbary wrote:
| Thinking more about this.
|
| I'd love to try v8 there, so we can benchmark the WebVM v8
| against the Native JS in the browser... all using the same
| engine (is a bit meta, isn't it?)
| apignotti wrote:
| Well, nodejs uses V8 and it's installed
| syrusakbary wrote:
| Exciting... trying it as I type!
|
| Edit: I'm trying to run the following benchmarks [1]:
| function mySlowFunction(baseNumber) {
| console.time('mySlowFunction'); let result = 0;
| for (var i = Math.pow(baseNumber, 7); i >= 0; i--) {
| result += Math.atan(i) * Math.tan(i); };
| console.timeEnd('mySlowFunction'); }
| mySlowFunction(8); // higher number => more iterations =>
| slower
|
| Results: 99ms in my Chromium browser (v8 JIT enabled), it
| breaks in the WebVM (after typing `node` and enter) with
| `TODO: FAULT af5147bf / CODE da d9 83`
|
| [1]: https://gist.github.com/sqren/5083d73f184acae0c5b7
| apignotti wrote:
| That's an unimplemented instruction. If I have to make a
| guess, one the trigonometric funcs you are calling. Feel
| free to report a bug if you'd like.
| Recursing wrote:
| As a smoke test, I tried running `time python3 -c
| 'print(max(range(2*10**7)))'`
|
| It's about ~10x faster on webvm.io compared to copy.sh/v86 and
| only ~20x slower than native, impressive stuff
| endisneigh wrote:
| What needs to happen to enable the browser to act as a
| functioning web server?
| apignotti wrote:
| It depends on the definition of "functioning".
|
| If you'd like to access a server from another tab / iframe of
| the same browser, that's almost possible already, just some UX
| work would be required.
|
| If you'd like users of the same page (or a separate specialized
| page) to connect, that could be possible with WebRTC.
|
| If you'd like arbitrary hosts to connect, that would require a
| server side proxy, there is no client-side only solution that I
| can see,
| mrtesthah wrote:
| Use Opera?
|
| https://www.ctrl.blog/entry/opera-unite.html
| dnautics wrote:
| we are well on the way towards the death of yavascript, let's
| hope there the exclusion zone doesn't come true.
| didip wrote:
| I always wonder if someone will eventually put Docker container
| up on the browser. It will make tons of experimentation work
| easy.
| mrtesthah wrote:
| is this some kind of joke to make computing as slow as
| possible?
| emteycz wrote:
| Some people don't care that it's slow. Availability and
| uniformity is much more valuable for example in school
| environment, especially at one where they teach IT one hour
| per week and the teacher is not really a programmer
| themselves.
| maltenuhn wrote:
| Nice! How does this compare to Web Containers
| (https://blog.stackblitz.com/posts/introducing-webcontainers/,
| proprietary to Stackblitz)?
| remisharrock wrote:
| From what I read on their website, web containers cannot run
| Linux binaries or compile c code or run python scripts / bash
| etc. - for example?
| mahoro wrote:
| Wow, this is amazing!
|
| Now we could create a /dev/dom virtual device, and write dynamic
| web pages in pure bash. I love this.
| colejohnson66 wrote:
| Or a DOMFS in /dom that's organized in the same hierarchy as
| the browser DOM. For example, to write a whole page:
| echo "...." > /dom
|
| Update the <title> tag: echo "TITLE" >
| /dom/html/head/title
|
| Change the charset: echo "EBCDIC" >
| /dom/html/head/meta[1].charset // second <meta> tag
| echo "EBCDIC" > /dom/html/head/1.charset // second child
| of <head>
|
| Even go full XPath. Replace a tag's inner HTML:
| echo "<div>abc</div>" > /dom/[@id='myID']
|
| This is a horrible idea...
| eurasiantiger wrote:
| Oracle Acquisitions team would like to discuss a business
| transaction.
| [deleted]
| westurner wrote:
| Is WebVM a potential solution to "JupyterLite doesn't have a
| bash/zsh shell"? The current pyodide CPython Jupyter kernel takes
| like ~25s to start at present, and can load Python packages
| precompiled to WASM _or_ unmodified Python packages with
| _micropip_ : https://pyodide.org/en/latest/usage/loading-
| packages.html#lo...
|
| Does WebVM solve for workload transparency, CPU overutilization
| by one tab, or end-to-end code signing maybe with W3C ld-proofs
| and whichever future-proof signature algorithm with a URL?
| miohtama wrote:
| The VM cannot have full TCP/IP stack, so any data research
| tasks are likely to need a special code paths and support for
| downloads. No SQL databases, etc.
| westurner wrote:
| From "Hosting SQLite Databases on GitHub Pages"
| https://news.ycombinator.com/item?id=28021766
| https://westurner.github.io/hnlog/#comment-28021766 :
|
| DuckDB can query [and page] Parquet from GitHub, sql.js-
| httpvfs, sqltorrent, File System Access API (Chrome only so
| far; IDK about resource quotas and multi-GB datasets),
| serverless search with WASM workers
|
| https://github.com/phiresky/sql.js-httpvfs :
|
| > _sql.js is a light wrapper around SQLite compiled with
| EMScripten for use in the browser (client-side)._
|
| > _This [sql.js-httpvfs] repo is a fork of and wrapper around
| sql.js to provide a read-only HTTP-Range-request based
| virtual file system for SQLite. It allows hosting an SQLite
| database on a static file hoster and querying that database
| from the browser without fully downloading it._
|
| > _The virtual file system is an emscripten filesystem with
| some "smart" logic to accelerate fetching with virtual read
| heads that speed up when sequential data is fetched. It could
| also be useful to other applications, the code is in
| lazyFile.ts. It might also be useful to implement this lazy
| fetching as an SQLite VFS [*] since then SQLite could be
| compiled with e.g. WASI SDK without relying on all the
| emscripten OS emulation._
| westurner wrote:
| Also, I'm not sure if jupyterlab/jupyterlab-google-drive
| works in JupyterLite yet? Is it yet possible to save
| notebooks and other files from JupyterLite running in WASM
| in the browser to one or more cloud storage providers?
|
| https://github.com/jupyterlab/jupyterlab-google-
| drive/issues...
|
| https://github.com/jupyterlite/jupyterlite/issues/464
| Klasiaster wrote:
| The VM could have its own TCP/IP stack, possibly with a SLIRP
| layer for translation of connections to the outside. Internet
| connectivity can be done by limiting it to AJAX, or
| forwarding the packets to a proxy (something like
| http://artemyankov.com/tcp-client-for-browsers/), or
| including a Tor client that connects to a Tor bridge, etc.
| westurner wrote:
| Is all of that necessary to LD_PRELOAD sockets and tunnel
| them over WebSockets, WebRTC, etc?
|
| So e.g. curl doesn't work without (File System Access API,)
| local storage && translation of e.g. at least _normal curl_
| syscalls to just HTTP /3?
| xiphias2 wrote:
| This looks awesome.
|
| Would it be possible to compile GNU/Linux to WASM as a target
| platform? What's missing for that?
| apignotti wrote:
| Hello HN, author of the post here, happy to answer questions.
| easrng wrote:
| Is there support for loopback networking (for IPC)? Is there a
| way to translate HTTP(S) requests to `fetch` requests? How
| difficult would it be to port a Go app that uses
| https://github.com/pion/webrtc to use the browser's native
| WebRTC?
| apignotti wrote:
| HTTP request could be intercepted, but due to CORS they would
| most likely not succeed. I have not studied the WebRTC
| protocol in detail but it might be possible.
| brian_herman wrote:
| How does this compare to https://bellard.org/jslinux/tech.html?
| https://bellard.org/jslinux/
| apignotti wrote:
| Perf. Our JIT is extremely advanced. Of course different
| workloads will behave differently, but you are welcome to try
| multiple payloads and see for yourselves.
| easrng wrote:
| And also https://copy.sh/v86
| remisharrock wrote:
| And jor1k (JavaScript openrisc processor emulator) : well,
| they emulate processors (x86, openrisc..) in JavaScript
| while WebVM execute (transpiled?) code in webassembly
| xmly wrote:
| How about the network stack? Is the VM can talk with other VMs
| from other browsers.
| apignotti wrote:
| Not in the current implementation, but absolutely possible
| with WebRTC. We have done something equivalent some time ago:
| https://medium.com/p/29fbbc62c5ca
| habitue wrote:
| Can you run containers in webvm?
| thekozmo wrote:
| Impressive stuff! Worth to try to run the OSv unikernel (one of
| my babies) in it.
| Klasiaster wrote:
| So, this is a reimplementation of the Linux ABI and no Linux
| kernel source is involved, right?
| apignotti wrote:
| That's correct.
| Klasiaster wrote:
| Have you tried compiling Linux as User Mode Linux with
| emscripten? I imagine something like this
| https://github.com/nabla-containers/nabla-linux would run
| on wasm, too?
| apignotti wrote:
| Well, User Mode Linux would still require an underlying
| Linux ABI, for example mmap to implement pagination. With
| sufficient work it might be possible to actually run UM
| Linux _on top_ of CheerpX / WebVM.
|
| Implementing the Linux ABI ourselves gives us the
| opportunity of a tighter integration with the Web
| platform anyway.
| [deleted]
| remisharrock wrote:
| Will you open source your code one day and if no, why not?
| arturventura wrote:
| Hey dude, I've been screwing around implementing plan9
| semantics in a OS like system for the browser
| (https://github.com/intigos/possimpible). I'm interested in
| using a x86 emulator inside a webwoker that I'm using for
| processes so I can run x86 code. How hard is something like
| this? Can you give me some pointers on how to start working on
| this? Thanks!
| btdmaster wrote:
| It seems to not work with my eager block settings. It works
| with a fresh Firefox profile though, so it's not clear what the
| issue exactly is though. I know for sure that the ext2 is never
| actually downloaded (0 byte response) and when I try to check
| anything in DevTools cxcore.wasm triggers a pause on debugger
| statement, which spikes the CPU.
|
| Any chance there could be a version with all the assets in one
| thing (say, GitHub Pages)?
| syrusakbary wrote:
| This is awesome. Really. Props to all the Leaning Tech team
| (creators of Cheerp, an alternative to Emscripten)!
|
| I believe it will be possible to achieve similar state in the
| future just using Native Wasm/WASI (so no transpilation from x86
| -> Wasm will be needed), but we are far from it given how slow
| the WASI standards move.
|
| The shell is impressive: https://webvm.io/ (only downloads ~5Mb
| of resources for a full Debian distro)
| apignotti wrote:
| Thanks, appreciated.
|
| By the way, it's spelled "Cheerp", with a lowercase p :-)
| syrusakbary wrote:
| Corrected!
| s5806533 wrote:
| Truly an impressive feat, and a lot of work no doubt. But why?
| Recently it seems to be some kind of fad to demonstrate that
| everything can be done inside a web browser. Again: why? Scope
| creep of web browsers is already beyond repair.
| remisharrock wrote:
| For educational uses, I have plenty of use cases for large
| scale teaching and learning, without backend servers and
| without installing anything complex on the client side.
___________________________________________________________________
(page generated 2022-02-01 23:00 UTC)