k6 VU(虚拟用户)需要多少内存? [英] How much memory for k6 VU (Virtual User)?

查看:230
本文介绍了k6 VU(虚拟用户)需要多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

k6 中的VU(虚拟用户)使用了多少内存?

How much memory is used by a VU (Virtual User) in k6?

VU的内存使用量是否线性扩展,即如果1个VU使用X千字节,那么100个VU是否使用100 * X千字节?

Does memory usage for VUs scale linearly, i.e. if 1 VU uses X kilobytes, do 100 VUs use 100 * X kilobytes?

推荐答案

VU占用的内存高度取决于脚本的功能以及(通常更重要的是)脚本导入/解析的其他文件数量.由于所有VU都有自己的JS VM,因此它们是需要解析的所有JS文件的单独副本.这样,如果您有一些较大的JS库,它将在VU之间复制,并且可能占您内存使用的大部分.如果您的脚本中还有一些包含大量测试数据的大文件-它们也将被复制,依此类推.以我的经验,简单的脚本可以使用1-2mb或更少的内存,而我看到在某些非常糟糕的情况下,脚本会导入一些相当大的JS库,而脚本的占用高达40mb.

How much memory a VU takes is highly dependent on what your script does and (usually more importantly) how many other files it imports/parses. Due to the fact that all VUs have their own JS VM they are separate copies of all JS files that need to be parsed. As such if you have some big JS library it will be copied between VUs and probably account for the majority of your memory usage. If your script also has some big files with a lot of test data in them - they will be copied as well and so on. In my experience simple scripts can use as little as 1-2mb or less and I have seen script go as high as 40mb in some really bad cases where they import some pretty big JS libs.

很明显,您的脚本在执行期间将使用更多的内存,但是该内存的主要来源将是响应主体,因此我们强烈建议使用 discardResponseBodies (在页面的最底部),以降低内存使用量,并仅在需要正文响应的位置/位置设置responseType.

Obviously your script will use more memory during the execution, but the major source of that memory will be response bodies so we highly recommend using discardResponseBodies (At the very bottom of the page) to lower that memory usage and only set responseType where/if you need the body response.

关于线性-在开始分析了JS脚本并初始化了所有VU之后,我分析过的每个脚本中的内存几乎都会分配给VU.它们使用的内存量大致相同,但是根据您使用的内存,k6的其他用途需要一些内存,大约200-300mb.

About linearity - kind of, more or less the majority of memory in every script that I have profiled goes towards VUs once the JS scripts have been parsed in the beginning and all the VUs have been initialized. And they use around the same amount of memory but there is some memory that k6 needs for other uses depending on what you use that should be around 200-300mb.

最终,您将必须测试脚本并查看.如果您知道要使用某些库,请导入它们而不使用它们,以便对其进行解析并快速估算.您可以使用--paused --no-teardown --no-setup运行k6仅初始化VU,而无需再次实际执行任何代码以进行更快的估计.我建议提供应使用-u <count>运行/初始化多少个VU进行测试.您应该等到进度条上显示paused为止,以便所有内容都已初始化. 请注意,k6首先会使用一些内存来解析您的JS并初始化其他内容,因此您可能应该开始使用至少50个VU进行测试,然后进行测试以查看为其他VU添加了多少内存.显然,执行最终脚本将使用更多的内存,但这对于进行测量非常有用.

Ultimately you will have to test your script and see. If you know that you are going to use some libraries import them without using them in order for them to parsed and to get a fast estimate. You can run k6 with --paused --no-teardown --no-setup to only initialize VUs without actually executing any of the code again for faster estimate. I recommend providing how many VUs should be ran/initialized with -u <count> for the testing. And you should wait until it says paused before a progress bar so that everything has been initialized. Be advised that k6 will use some memory to parse your JS and initialize other stuff in the beginning so you should probably start testing with at least 50 VUs and go up in order to see how much memory is being added for the additional VUs. Obliviously execution of the final script will use more memory but this should be useful for gauging purposes.

这篇关于k6 VU(虚拟用户)需要多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆