Val Town Blog 10月02日 20:56
Val.town 推出更快的 HTTP Val 运行时预览
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Val.town 发布了新的 HTTP Val 运行时预览版,旨在显著提升性能,尤其在处理大量请求时。新运行时通过保持 Deno 进程活跃,减少了每次请求的冷启动时间,从而实现高达 5 倍的速度提升。用户可以通过将 Val 类型从 HTTP 切换到 HTTP (Preview) 来体验此功能。虽然该预览版存在一些限制,例如日志输出和取消运行中的 Val,但开发者社区对此表示期待,并可通过 Discord 或邮件提供反馈。新运行时有望成为未来的默认选项,为用户带来更高效的 Val 服务。

🚀 **性能显著提升**:新的 HTTP Val 运行时通过复用 Deno 进程,大幅减少了冷启动时间,对于简单的 Val,后续请求速度提升可达 10 倍,整体速度提升高达 5 倍,尤其在处理大量请求时效果显著。

💡 **预览版与使用方式**:新运行时以“HTTP (Preview)” Val 类型提供,用户只需在创建或编辑 Val 时从下拉菜单中选择该类型即可启用。这使得开发者能够先行体验并提供反馈。

⚠️ **当前限制与注意事项**:预览版目前不支持 `console.log` 等日志输出,且无法取消运行中的 Val。此外,有一个重要的破坏性更改:只有 Val 的 handler 会在每次请求时重新运行,handler 之外的代码(如初始化时执行的代码)仅在 Val 启动时运行一次。开发者需要将每次请求都需要执行的代码移至 handler 内。

📈 **未来展望与反馈**:Val.town 计划在完善预览版并实现与现有运行时功能对等后,将其设为默认选项,并移除“(Preview)”标识。社区可以通过 Discord 频道或电子邮件提供反馈,帮助 Val.town 改进此项重要更新。

💰 **长期可用性考虑**:为了支持更长时间的 Val 运行,Val.town 正在考虑调整定价策略,以确保可持续性,并可能为 Pro 用户提供更长的超时窗口,甚至探索无限期保持 Val 运行的可能性。

New HTTP Val Runtime in Preview

on

We built a new runtime for HTTP vals that is much faster at scale. We’ve seen up to a 5x speedup for some vals. This is a preview feature, so expect rough edges. We’d love your feedback on it.

We created a new val type, HTTP (Preview), to let you opt-into the new runtime. Here’s how:

    Create a normal HTTP valClick on the val’s type HTTP and select HTTP (Preview) in the dropdown menu.

That’s it! Run your val 5 times in quick succession to see the difference.

Up until now, every time you run a val it starts a new Deno process and installs all your dependencies from scratch. This takes 100 milliseconds or more, depending on how many dependencies you have.

With the new HTTP (Preview) val, we keep your Deno process around and forward multiple requests to it. This means that the first request will still have the 100ms+ cold start time, but every request after that will be much faster. For example, the simplest possible val that just returns “hello world!” will take 100ms to boot up the first time, but then only 10ms for subsequent requests. To be clear, that’s not including network latency to the val (which from NYC is 90ms), just the time it takes for the val to respond.

A user from NYC hitting a “hello world!” val can expect to see a 180ms response time for the first request and 90ms for every request after that using HTTP (Preview). Whereas with the normal HTTP val type, they would see 190ms for every request. The difference is even more pronounced for vals with more dependencies and large dependencies like WASM modules. We migrated the Date Me Directory and saw total request time go from 800ms to 200ms!

We want to be conservative with this rollout, so we’re only keeping HTTP (Preview) vals alive for 10 seconds after the end of the last request they receive. As we get more comfortable keeping vals alive for longer, we’ll increase this timeout window, particularly for Pro users. We’re considering ways to keep vals alive indefinitely, but that will require some changes to our pricing to make it sustainable.

There are currently two limitations to HTTP (Preview) compared to the normal HTTP type:

    console.log and other logging output aren’t capturedYou can’t cancel a val that is currently running

We expect to have fixes for these limitations in the next couple weeks. In the meantime, we recommend using the normal HTTP val type in development and then switching to HTTP (Preview) for production.

There is one breaking change with this new feature: it only re-runs your val handler, not any of the other code in your val. This means that if you have any code outside of your handler that you want to run on every request, you’ll need to move it into your handler.

For example, this val will return a new random number for every request in our existing system, but after you switch to the next version, it’ll return the same number - because the call to Math.random() is only run when the val is started up, not when a new request is handled.

const number = Math.random();

export default function(req: Request) {

return Response.json(number);

The upgrade path is to move anything you want to happen on every request into the request handler:

export default function(req: Request) {

const number = Math.random();

return Response.json(number);

Now each call to this val will return a new random number. This is how most serverless platforms work, and we think it’s a good model to follow. You’ll only need to migrate your code if you upgrade to the new runtime.

This new runtime has the potential to be much faster and more scalable than our current approach, so we want it to be the default soon. But it’s a big change, so we’re being careful. Today we’re rolling it out as an opt-in val type, HTTP (Preview).

After we’ve ironed out the kinks and achieved feature parity between the two runtimes, we’ll make this the default type for new HTTP vals,drop the (Preview), and encourage everyone to upgrade to the new system for that big performance boost! Depending on how it works out, we might be also be able to auto-upgrade some vals to the new system.

We’d love to hear your feedback on this new feature. You can send a message in our #general or #bugs channels in our Discord or email us at feedback@val.town.

Edit this page

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Val.town HTTP Val Runtime Performance Preview Serverless Deno Optimization API Developer Tools
相关文章