Better HN
topnewbestaskshowjobs
Log inSign up

CompuIves

252 karma · joined Aug 14, 2015 (11y ago) · 95 submissions

Ives (but you can also call me Flip)

- Co-Founder Biscuit (biscuit.so) - (Previously) Co-Founder of CodeSandbox, acquired by Together

My email is first name @ biscuit.so

meet.hn/city/nl-Amsterdam

Socials: - x.com/compuives

---

Submissions

comment 4y ago · link · parent

It could be shared memory all the way through, but the memory of the original VM should become read-only once a cloned VM starts reading from it. So then both VMs (the original VM and the new VM) should put their writes in a new CoW layer.

Using XFS with CoW has been the easiest way to enable this, but if there's a way that we can do this purely in-memory, that would be even faster.

That said, for hibernation we would still have to persist to disk, but timing is less important there.

comment 4y ago · link · parent

Thank you! Right now our main use case is cloning development environments so we can provide a fresh running dev env for every branch and PR. However there are many other interesting applications, like speeding up CI jobs with VMs that start from a snapshot.

I'll make sure we write about the other topics as well. For the network, we run the VM in its own network namespace on the host, and we give every VM the same IP. We then use an iptable rule to rewrite every incoming and outgoing packet to the IP that the host has assigned for the VM.

comment 4y ago · link · parent

The biggest VM we've been running for dev environments have 12GB RAM, 8vCPUs and 30GB disk. I've also done some tests with 16GB RAM and that worked well too. Have yet to find an upper limit.

Another (unrelated) test we've done is on overprovisioning memory. We were able to run 200 VMs (all running Vite dev server where a file was changed every second) with 2GB RAM per VM, on a node with 128GB RAM. Because we were mapping the memory files on disk directly to the VM, the VM would automatically "swap" the memory back to the memory file when it had memory pressure. The bottleneck here was CPU.

comment 4y ago · link · parent

Firecracker keeps a bitmap of which pages have been dirtied (it's a flag you can turn on), so you can make incremental snapshots of only the changed pages (more here: https://github.com/firecracker-microvm/firecracker/blob/main...).

In our case we changed Firecracker to use a shared mmap instead of an private mmap, so in our case the dirtied pages were synced back automatically to the backing memory file. The main reason for this was to reduce IO on snapshot time. I'm also looking at other ways we can do this, because using a shared mmap fragments the underlying xfs fs pretty fast. Maybe we can batch writes more instead of writing single pages.

comment 4y ago · link · parent

Thanks for sharing the paper, that is super interesting. This is indeed a challenge. The fact that we run development workloads instead of production workloads makes this easier for our use case. We do some rehydration, and when forking across team/organization boundaries we don't clone if there are secrets set. But for production workloads this would not be ready yet.

Once uniqueness has been solved though, VM cloning would become a real solution for serverless hosting (and many of other cases), exciting prospect!

comment 4y ago · link · parent

Firecracker is one of the most exciting technologies I've seen in a while. It felt like a whole world opened up after learning about its capabilities.

comment 4y ago · link · parent

Send me an email at my name @ codesandbox.io, then we can plan something!

comment 4y ago · link · parent

This looks amazing, really nicely done.

I'm the co-founder of CodeSandbox and it's super cool to see Sandpack used this way in the wild! We've been working on a way to run VMs with Sandpack, maybe we could work together on it if you're interested!

69.

How we clone a running VM in 2 seconds(codesandbox.io ↗)

12 points · by CompuIves · 4y ago · 1 comment

comment 4y ago · link · parent

Ahhh I see. Yep, we should have better messaging there. With CodeSandbox you can run _anything_, since we allow you to run any Docker container. I've been running it with Elixir and Rust as well. We do have a focus on making the web development experience seamless first though.

The plans currently don't reflect the beta of Projects, there we do have specs (by default 4vCPUs + 4GB RAM) with upgrades up to 12GB RAM and 8vCPUs. We're still exploring other machine specs there too.

The place where this differentiates is that every branch runs its own dev env, based on a memory snapshot from the main branch. This way when you switch branches, you switch to a new environment and you won't have to think about running migrations/installing dependencies/pulling changes just for that branch.

comment 4y ago · link · parent

What would you say makes it more limited? In the end you get a VM where you can run Docker/Nix etc...

comment 5y ago · link · parent

Yes, after every compilation we send the full bundler state. This is saved on the context so you can use that to analyze the output. In one of the examples in the blog post we show the transpiled code for example.

A hidden "feature" is that we automatically run tests defined (e.g. index.test.js) using jest, and dispatch the test results. So you can listen to that as well.

comment 5y ago · link · parent

Also, while it uses the CodeSandbox bundler, you can self host it so it's not dependent on our servers!

comment 5y ago · link · parent

First of all, super cool to hear that you've been such an early adopter of CodeSandbox! Not many can say that.

The fact that we made your projects public and kept charging is definitely a big mistake, and shouldn't have happened in the first place. When you cancel a subscription, we should keep your existing work private. Could you send me an email at ives@codesandbox.io so we can fix it?

Apologies for the fact this happened to you, that's a severe mistake and shouldn't have happened!

comment 5y ago · link · parent

Yep, it downloads and compiles dependencies on the client side. However, it does this on a different domain for security reasons.

comment 5y ago · link · parent

Replay has been amazing for me to debug hard to reproduce issues like live collaboration issues. You just record the bug, share it with others, place some console.logs (after the fact!) and scrub through the recording to see where things went wrong.

Also nice side-effect is that it's amazing to explore other code-bases, just being able to put a console.log somewhere to see how often it's run when using an application is a lot of fun.

comment 6y ago · link · parent

The exact same has happened with CodeSandbox, Google Domains had blocked our csb.dev (internal domain) and csb.app (domain for projects) without any warnings. It took us two days (of downtime!) to get them to lift the block. But then after 3 weeks, they did the exact same thing! They blocked us again for reports without warning. Luckily we had a fallback domain so that there was not much service disruption, but it was extremely frustrating working with them on this.

After 3 sudden blocks from them, they now give us a warning before they're planning to block us, but it took many calls before we got to that stage.

comment 6y ago · link · parent

We've been using Elixir for our API server from the start. It's a great language and scales really well. We needed to add a websocket API at some point, and now it's our channel with most throughput. Phoenix handles it fine, and we're still able to triple the throughput comfortably.

The one thing that we struggled with Elixir with is that it's quite hard to find people that know Elixir. For a long time I was the only one doing Elixir in the company, which introduced a bottleneck. That said, when you find someone who knows Elixir they tend to know Elixir (and a bit of infra) quite well.

comment 8y ago · link · parent

That's a really good point! I deployed a new update with .pug support in vanilla, here's a sandbox to play with it: https://codesandbox.io/s/mjln1846k8.

comment 8y ago · link · parent

I am so happy that we're on Hacker News!

If you have any questions about how things work in CodeSandbox don't hesitate to ask me! I'll watch this thread to answer any questions.

comment 8y ago · link · parent

Hello! Creator of CodeSandbox here!

I don't want to give a comparison of StackBlitz and CodeSandbox, because my view as one of the creators would be skewed. I want to note though that CodeSandbox existed before StackBlitz released, I published CodeSandbox in April ([1] [2]) and StackBlitz released in August [3].

[1] https://hackernoon.com/codesandbox-an-online-react-editor-b8...

[2] https://news.ycombinator.com/item?id=14022860

[3] https://medium.com/@ericsimons/stackblitz-online-vs-code-ide...

comment 8y ago · link · parent

I moved the sandbox to here: https://codesandbox.io/s/3rrq6yx9v1. I'm also curious, how did you find out about the sandbox.config.json? I feel like it's pretty undocumented by now, we could definitely improve on that.

comment 8y ago · link · parent

1) Thank you!

2) Ah that's really stupid of me, `.stream` was our staging server. I should mention this somewhere, codesandbox.io should have the latest version with live.

3) Good one! I'll update it.

4) That's a super nice sandbox, I love tutorials that use gameplay, makes it much more fun to learn. I'd move it to the io domain, because our stream database is horribly outdated. I'll add a redirect from stream soon to avoid confusion.

comment 8y ago · link · parent

Thank you! Yeah we moved to Kubernetes yesterday!

I learned most from the official Kubernetes tutorials (https://kubernetes.io/docs/tutorials/). I also used mix_docker (https://github.com/Recruitee/mix_docker) as a reference on how to build the image. The advantage of Kubernetes is that you can have the same way to deploy for all servers, so if you learn how Kubernetes deploys you automatically know how to deploy Phoenix applications.

comment 8y ago · link · parent

Ah, I always forget to keep that page up to date. I'm sorry for that. Since CodeSandbox 2.5 we got some new things, like Parcel support, Typescript configuration support and some other things. I'll make sure to keep that page more up to date.

And if you really want to make sure, we're open source: https://github.com/CompuIves/codesandbox-client.

comment 8y ago · link · parent

Thank you very much! It was definitely one of the most fun features to build.

I started working on this on March 15th, and the past few days was about testing everything, preparing the release and squashing bugs. The advantage of this type of functionality is that there are tons of high quality papers and articles already written on the subject, especially this one helped me a lot: http://www.codecommit.com/blog/java/understanding-and-applyi.... There were a lot of sleepless nights involved too.

I'm not sure about the VS Code and Atom teams, but I imagine that there are more constraints and there is more functionality to implement since they work with hundreds of potentially big files. I think those factors make it harder to implement this functionality than in the case of CodeSandbox.

comment 8y ago · link · parent

Thank you very much! I appreciate it.

comment 8y ago · link · parent

Thank you! Our backend server is an Elixir (Phoenix) server. It has a separate Elixir process for every current live room, we store all state in Redis. So in case we do a rolling deploy we won't drop any connections and continue where we stopped.

The server is mostly responsible for keeping all room state (the editors, the owner, operations per module) and transforming operations. When an operation comes in at the server, like an insertion, the server will check what revision that operation is at and transform it accordingly if the sent operation is based on outdated code. Then that operation will be broadcasted to the clients and again transformed on the clients to handle any inconsistency.

The library we use for doing the transformations is called ot_ex.

I hope this quick view is clearly written, let me know if there are any other questions!

comment 8y ago · link · parent

Hey everyone! I'm the author of this post, I'll be here to answer any questions.

comment 9y ago · link · parent

I did see that tweet. Maybe I was a bit unclear. I mean that the whole editor itself doesn't open when you don't have a connection (at least for me). My reproduction steps are:

1. Open https://stackblitz.com/fork/react

2. Disconnect from internet

3. Refresh the tab

At least for me this gives me a 404. I'm on Chrome. However, when I open the preview tab while offline it doesn't 404 on me.

1234