简体   繁体   English

优化Node.js AWS Lambda

[英]Optimize nodejs aws lambda

I have a nodejs lambda to get data from a url. 我有一个nodejs lambda来从URL获取数据。 When I began to develop it I had all the code in a single file and just required a single module installed via npm. 当我开始开发它时,我将所有代码都放在一个文件中,只需要通过npm安装一个模块即可。 Now I'm trying to make things a little bit clearer for futures developers and I am separating the code in several files. 现在,我正在尝试为期货开发人员弄清楚一些事情,并将代码分成几个文件。 The plan is to zip all the files later. 计划是以后压缩所有文件。 The case is that I don't know if this could cause a worst performance due to te require statements. 情况是,我不知道由于te require语句是否会导致最差的性能。

I've been thinking on use webpack to bundle all js files in a single file and serve it that way. 我一直在考虑使用webpack将所有js文件捆绑在一个文件中并以这种方式提供。 It could be better? 它还可以更好?

The best way to find out is to give it a try. 找出答案的最佳方法是尝试一下。 I'd say start with requiring because it will make the code and the process of deployment simpler, then if you notice performance issues try with Webpack and see if there are improvements. 我要说的是从require入手,因为它将使代码和部署过程更加简单,然后,如果您发现性能问题,请尝试使用Webpack并查看是否有改进。 This sounds a little like premature optimisation. 这听起来有点像过早的优化。

Regarding the require statements - depends on how big the files you require are. 关于require语句-取决于所需文件的大小。 In my experience, requiring modules in lambda hasn't had significant performance effects at all. 以我的经验,在lambda中要求模块根本没有显着的性能影响。 I'd say the cold start will probably take a bit longer, but after that the modules will be cached for reuse and it will be all good. 我想说,冷启动可能需要更长的时间,但是在那之后,模块将被缓存以供重用,并且一切都会很好。

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

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