简体   繁体   English

我如何在 ParcelJS 中找到 memory 泄漏(或什么占用了这么多内存)?

[英]How can I find a memory leak (or what is taking up so much memory) in ParcelJS?

I'm running ParcelJS 2 in a BitBucket pipeline bundling up an app, but our pipelines sporadically runs out of memory.我在捆绑应用程序的 BitBucket 管道中运行 ParcelJS 2,但我们的管道偶尔会用完 memory。

I want to be able to pin-point where the problem comes from - whether that is a single node module dependency, or if it's just a problem with ParcelJS overall.我希望能够查明问题出在哪里 - 无论是单节点模块依赖性,还是只是 ParcelJS 的整体问题。

I've tried logging out the memory usage in the CI container while the build is taking place, and I can see it's hitting the max memory towards the end of the build - sometimes this causes a crash and sometimes doesn't.我已经尝试在构建过程中注销 CI 容器中的 memory 使用情况,我可以看到它在构建结束时达到最大值 memory - 有时这会导致崩溃,有时不会。 I've done that by running this command in the pipeline:我通过在管道中运行此命令来完成此操作:

- while true; do ps -aux && sleep 30; done &
- while true; do echo "Memory usage in megabytes:" && echo $((`cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes | awk '{print $1}'`/1048576)) && sleep 0.1; done &

Which outputs...哪些输出...

4082
Memory usage in megabytes:
4083
Memory usage in megabytes:
4093
Memory usage in megabytes:
4095
Memory usage in megabytes:
4095
Memory usage in megabytes:
4094
Memory usage in megabytes:
4095

etc...

Any advice on how to go about pin-pointing where the problem could be?关于如何定位问题所在的 go 有什么建议吗?

Thanks in advance.提前致谢。

This is a good command to use and it seems to work fine for Bitbucket Pipelines and possibly other CI/CD services, like GitHub Actions and GitLab CI/CD.这是一个很好用的命令,它似乎适用于 Bitbucket 管道和可能的其他 CI/CD 服务,例如 GitHub 操作和 GitLab CI/CD。 It displays the memory usage inside the Docker container, in real-time, during a CI/CD build.它在 CI/CD 构建期间实时显示 Docker 容器内的 memory 使用情况。

Here are some references and tutorials about the Docker memory usage commands:下面是Docker memory使用命令的一些参考和教程:

As you already know, Bitbucket Pipelines has a strict limit on the memory usage of each Docker container.众所周知,Bitbucket Pipelines对每个Docker容器的memory使用量有严格的限制。 By default, each build step has 4 GB of memory available:默认情况下,每个构建步骤都有 4 GB 的 memory 可用:

To pin-point the large memory use, consider changing the sleep time to 2 or 5 seconds, and perhaps add a timestamp to each message, using the " date " command.要查明 memory 的大量使用,请考虑将休眠时间更改为 2 或 5 秒,并可能使用“ date ”命令为每条消息添加时间戳。 Then check which command was run at the time of the large memory increase.然后查看memory增幅较大时运行的是哪个命令。 Double-check if this command is creating too many threads or processes, or if it's opening too many files at the same time.仔细检查此命令是否创建了太多线程或进程,或者它是否同时打开了太多文件。 The command may have some flags that you can use to reduce the number of threads or processes that it creates.该命令可能有一些标志,您可以使用这些标志来减少它创建的线程或进程的数量。

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

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