aayushmau5 / tour-of-elixir

An attempt at building a tour of elixir using phoenix, liveview and containers(WIP).
MIT License
0 stars 0 forks source link

Implementation details #1

Open aayushmau5 opened 8 months ago

aayushmau5 commented 8 months ago

How do we go on about creating this project?

Ideas

I was thinking we can use liveview for UI, and use microVMs(like firecracker) to execute user input code.

For contents, we can take inspiration from: A tour of Go and Gleam tour.

Implementation

Currently i don't know anything about running VMs through elixir code, so can't comment on that front.

# Very minimal architecture
UI(browser) <-> LiveView Process <-> Code Runner process <-> microVMs

Any contributions are welcome :)

TwistingTwists commented 8 months ago

https://github.com/E-xyza/ex_term

check this out.

This gives you a terminal component in liveview.

TwistingTwists commented 8 months ago

Here are a few considerations.

  1. since this project aims at running arbitrary code => it might make sense to go through this https://github.com/TheFirstAvenger/safe_code
  2. another way of safety would be through , FireCracker VM instance for each example. or each page. Can be discussed.
aayushmau5 commented 8 months ago

another way of safety would be through , FireCracker VM instance for each example. or each page. Can be discussed.

I was thinking one VM instance per liveview process.

TwistingTwists commented 8 months ago

another way of safety would be through , FireCracker VM instance for each example. or each page. Can be discussed.

I was thinking one VM instance per liveview process.

That could work. It might be premature optimisation to design for scale just yet. But we should consider all alternatives and build the easiest / safest. (whatever ships fast)

My reservation around VM instance per liveview process is : boot time. (~150 ms) and memory consumption (___ MB)

One model that could work for elixir is how cloudflare workers are architected. https://blog.cloudflare.com/cloud-computing-without-containers

They don't spin containers! But they leverage isolates in V8 to sandbox workers. So, essentially the VM is always up. That idea can be taken further for elixir => because for beamvm , these processes could be clustered !

aayushmau5 commented 8 months ago

My reservation around VM instance per liveview process is : boot time. (~150 ms) and memory consumption (___ MB)

Right. We can try to evaluate which works better for us in terms of memory consumption. iirc microVMs have less memory consumption as compared to docker.

That idea can be taken further for elixir => because for beamvm , these processes could be clustered !

cool idea! what's the isolates alternative in beam world? or perhaps we can use https://github.com/TheFirstAvenger/safe_code?

TwistingTwists commented 7 months ago

Will have to dig for finding isolates for beam world.