简体   繁体   English

用于 firebase 函数的 NestJS:开始时间是否适合生产?

[英]NestJS for firebase functions: are the start times production-suitable?

There's plenty of articles on how to set up firebase functions with nestjs, and I've been developing this for about a month now on my local machine.有很多关于如何使用 nestjs 设置 firebase 函数的文章,我已经在我的本地机器上开发了大约一个月。 Finally, it was time to release.最后,是时候发布了。 I used a combination of nestjs and mikro orm to handle my server and database layer, with 12 entities and around 20 routes.我使用 nestjs 和 mikro orm 的组合来处理我的服务器和数据库层,有 12 个实体和大约 20 条路由。 Everything ran smooth as butter locally.在当地,一切都像黄油一样顺利。

However, in a firebase functions environment (defaults) where you have 256mb of RAM and god knows how much vCPU, suddenly my cold start + 30ish seconds of nest spinning up, it meant that it's no longer a production ready environment.然而,在一个 firebase 函数环境(默认值)中,你有 256mb 的 RAM,天知道有多少 vCPU,突然间我的冷启动 + 30 多秒的嵌套旋转,这意味着它不再是生产就绪环境。 In contrast, express spun up in around 500ms + cold start time.相比之下,快递在大约 500 毫秒 + 冷启动时间中旋转起来。

Here's a few log screenshots to show the time each step took:下面是一些日志屏幕截图,以显示每一步所花费的时间:

在此处输入图像描述

在此处输入图像描述

Could I have architected my application incorrectly or is Nest just that slow in tiny environments?我的应用程序架构可能不正确,还是 Nest 在微型环境中速度太慢? I can't imagine lazy loading would help, and im auto discovering entities for mikro orm. Is there anything I can try to speed up the process or does anyone have any experience with nestjs in firebase functions?我无法想象延迟加载会有所帮助,并且我会自动发现 mikro orm 的实体。有什么我可以尝试加快这个过程的,或者有没有人在 firebase 函数中使用过 nestjs?

NestJS has a guide on optimizing serving in environments that have cold starts. NestJS 有一个关于在冷启动环境中优化服务的指南 That might be a good place to start.这可能是一个很好的起点。

For any case where a lot of setup work has to be done on cold start (like the 30 seconds of NestJS spinning up that you're experiencing), the minInstances option may be worth using.对于必须在冷启动时完成大量设置工作的任何情况(例如您正在经历的 NestJS 旋转 30 秒), minInstances选项可能值得使用。 It lets you keep a minimum number of instances "hot" so that there is a lower chance of an end user experiencing a cold start.它可以让您保持最少数量的“热”实例,从而降低最终用户遇到冷启动的可能性。

You can also try adjusting the amount of memory available to the function with the memory option (more memory gives you more CPU too).您还可以尝试使用memory选项调整 memory 可用于 function 的数量(更多的 memory 也会为您提供更多 CPU)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM