我们在2秒钟内克隆了一个正在运行的虚拟机(2022年)。
We clone a running VM in 2 seconds (2022)

原始链接: https://codesandbox.io/blog/how-we-clone-a-running-vm-in-2-seconds

CodeSandbox 通过利用 Firecracker 微型虚拟机和创新的内存快照技术,实现了近乎即时的环境克隆(不到 2 秒)。传统的在浏览器中运行代码的方法对于大型项目来说限制重重。Firecracker 微型虚拟机可在几毫秒内启动,为传统的虚拟机提供了一种轻量级的替代方案。 关键的突破在于快照技术的优化。他们没有在快照过程中将内存完全写入磁盘,而是利用 `mmap` 和 `MAP_SHARED` 来延迟同步更改,从而将快照时间从几秒减少到几毫秒。对于克隆,他们为内存快照和磁盘实现了写时复制 (CoW)。这避免了冗余的数据复制;克隆的虚拟机最初共享原始数据,只有在进行修改时才复制。这大大减少了克隆时间。这使得无缝的工作流程成为可能,例如即时分叉具有预配置环境的分支,并使诸如即时 Minecraft 服务器克隆之类的服务成为可能。这种新方法为每个拉取请求创建了一个开发环境。

这个Hacker News帖子讨论了一篇2022年的文章,文章介绍了如何利用CodeSandbox的基础设施在2秒钟内克隆虚拟机(VM)。原作者CompuIves提供了他们进度的更新,包括使用userfaultfd绕过磁盘以实现更快的克隆,以及使用zstd压缩内存快照以实现更快的启动。 讨论随后深入探讨了内存克隆的安全性问题,特别是加密库中nonce重用的问题,如果熵没有立即刷新,这可能会导致漏洞。用户讨论了虚拟机与容器的优缺点,虚拟机技术适应现代需求的潜力以及实时进程迁移的挑战。几位评论者提到了现有的技术,例如VMware的vSphere Fault Tolerance和Google的实时迁移,这些技术执行类似的功能。最后,一位用户表达了对在线文章质量的失望,这些文章越来越多的是AI生成的,缺乏真实的基准测试。

原文

At CodeSandbox we run your development project and turn it into a link you can share with anyone. People visiting this link can not only see your running code, they can click “fork” and get an exact copy of that environment within 2 seconds so they can easily contribute back. Give it a try with this example, or import your GitHub repo here!

So how can we spin up a cloned environment in 2 seconds? That's exactly what I'll be talking about here!

The challenge: spinning up a development environment in two seconds

We've been running sandboxes for a long time now, and the core premise has always been the same: instead of showing static code, it should be running. Not only that, you should be able to press fork and play with it whenever you want to.

In the past, we've enabled this experience by running all your code in your browser. Whenever you would look at a sandbox, you would execute the code. This was fast, because we had full control over how the code was bundled. Forks were fast:

联系我们 contact @ memedata.com