Code Monkey home page Code Monkey logo

icumonitor's Introduction

ICUMonitor: a sample .NET application on Enarx

This is a sample application, based on Steve Sanderson's Greenhouse Monitor, showing a typical ASP.NET Core code, including nontrivial features like WebSockets (via SignalR) and gRPC-Web, can work unmodified when built as a WASI-compliant .wasm file and run inside wasmtime and enarx.

Install the prerequisites

  • Install .NET 7
    • Download the dotnet-install scripts
    • On Debian, install the following packages: sudo apt-get update && sudo apt-get install build-essential cmake npm mono-devel dotnet --list-sdks
    • Run sudo chmod +x ./dotnet-install.sh
    • Install the following .NET version: ./dotnet-install.sh --channel 7.0 --version 7.0.100-preview.5.22307.18
    • Export paths: export DOTNET_ROOT=$HOME/.dotnet and export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools
  • Install Node.js to build the Svelte UI
  • Install Wasmtime or Enarx to run the .NET application

Clone and build ICUMonitor

  • Clone the ICUMonitor repository:
    • git clone https://github.com/enarx/ICUMonitor.git
  • Build the Svelte UI
    • cd ICUMonitor/src/ICUMonitor/UI
    • npm install
    • npm run build
    • cd ../../..
  • Build the .NET application
    • cd src/ICUMonitor
    • dotnet build

Run ICUMonitor

  • cd src/ICUMonitor (unless you're already there)
  • Run on dotnet:
    • dotnet run
    • Or, if you're using Visual Studio, press Ctrl+F5
  • Run on wasmtime:
    • wasmtime bin/Debug/net7.0/ICUMonitor.wasm --tcplisten 0.0.0.0:5000
  • Run on enarx:
    • enarx run --wasmcfgfile ./Enarx.toml ./bin/Debug/net7.0/ICUMonitor.wasm
  • Browse to http://localhost:5000
  • Remember to do a dotnet build each time you make further code changes
  • This assumes wasmtime or enarx are available on your system PATH

Send some simulated sensor data via gRPC-Web

  • Leave the ICUMonitor app running, and open a new terminal window
  • cd src/SensorSimulator
  • dotnet run

Attach a debugger

  • Start the application using this command:
    • wasmtime bin/Debug/net7.0/ICUMonitor.wasm --tcplisten 0.0.0.0:8001 --tcplisten 0.0.0.0:11000 --env DEBUGGER_FD=3
    • Open VS Code inside the src/ICUMonitor directory (e.g., run code . from there)
    • Ensure you have the Mono Debugger extension installed
    • Set a breakpoint somewhere in the .NET code
    • Go into VS Code's "Run and debug" tool and click Attach
    • You should see the console output Accepted connection from client, socket fd=5 and then, shortly after, Now listening on...
    • At this point, if you do something to cause the breakpoint to be hit, you should see it in VS Code

Caveats

The Wasi.Sdk is a very early experimental preview, and many things aren't yet implemented. In particular, .NET's garbage collection is not enabled at all, so over time the memory usage will grow indefinitely until the application terminates. This happens after handling several hundred HTTP requests. This is obviously something we intend to fix soon.

Another issue you may encounter is that wasmtime's sock_accept support has some bugs. For example if a client disconnects ungracefully while a TCP connection is open, then the wasmtime process will terminate (this is particularly the case on Windows).

About the included package binaries

Normally people don't bundle the .nupkg package binaries with their application sources, so you may be wondering why there are ~15 MB of binaries in the packages/ directory in this repo. It's simply because the version of Wasi.Sdk that supports debugging isn't yet published to the public NuGet feed. Once the latest package builds are published, it would not be necessary to have the packages/ directory in this repo at all.

icumonitor's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.