压测出现 no such file or directory, scandir 'XXX'

查看 88|回复 9
作者:yuuk520   
一个基于 next.js 的项目使用 JMeter 在 docker 容器中进行压力测试,当并发数过高时,会出现以下错误,但该目录确实是存在的,并且随着并发数变高报错也变多。正常访问就不会出现。
错误出现的代码在此: https://github.com/i18next/next-i18next/blob/205e9a4fe5d5d1baca9f5a82561096b6372e1432/src/config/createConfig.ts#L211
2023-12-25 07:47 +00:00: Error: ENOENT: no such file or directory, scandir '/app/packages/eshop/public/locales/cn'
    at Object.readdirSync (node:fs:1405:3)
    at getLocaleNamespaces (/app/node_modules/next-i18next/dist/commonjs/config/createConfig.js:214:16)
    at /app/node_modules/next-i18next/dist/commonjs/config/createConfig.js:231:20
    at Array.map ()
    at getNamespaces (/app/node_modules/next-i18next/dist/commonjs/config/createConfig.js:230:44)
    at createConfig (/app/node_modules/next-i18next/dist/commonjs/config/createConfig.js:271:29)
    at _callee$ (/app/node_modules/next-i18next/dist/commonjs/serverSideTranslations.js:201:53)
    at tryCatch (/app/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:44:17)
    at Generator. (/app/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:125:22)
    at Generator.next (/app/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:69:21) {
  errno: -2,
  syscall: 'scandir',
  path: '/app/packages/eshop/public/locales/cn'
}
报错指向的是用的一个 next.js 的多语言库 next-i18next ,它在每次页面刷新的时候都会调用 fs.readdirSync 读取本地多语言 json 文件。
我也试过在容器里面大量调用(定时器模拟) fs.readdirSync 也没出现报错。
实在不知道是什么原因引起的...有了解的小伙伴吗?

App, dist, CommonJS, config

thinkershare   
我也遇到过,不知道什么原因,感觉是 I/O 句柄被耗尽了。
yuuk520
OP
  
@thinkershare 如果是这种情况有什么工具可以监测到吗?
namelesswryyy   
试试把资源一起打包到 docker ,不要挂载上去
如果要是 docker 在 windows 上的话,那就是 windows 锅
yuuk520
OP
  
@namelesswryyy 不太理解,能具体说下打包上去和挂载上去区别么?
cloverzrg2   
宿主机的 `ulimit -a` 返回啥?尝试设置一下? `ulimit -n 100000`
另外,docker 的参数尝试加下
`docker run --ulimit nofile=262144:262144`
zhangky   
如果资源内容不变,不需要每次都读,可以做个缓存。
luojiyin87   
docker 默认是没 ulimit ,可以打开无限的 I/O 句柄,不会主动释放,耗尽主机的 I/O 句柄。
```shell
grep 'Limit' /lib/systemd/system/docker.service
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
```
但是主机内是有 ulimit ,可以分配给 docker 的 I/O 句柄是有限。
```shell
ulimit -n
1024
```
1 调高主机的 ulimit ,2 限制 docker 的 ulimit
yuuk520
OP
  
@zhangky 理论是这样,不过就得改这个第三方库了
ntedshen   
在 wsl 下使用 await fs.readdir 读取文件过多的文件夹时候也遇到过。。。
怀疑是某种 os 内置的超时。。。
因为没当回事所以没试过修改 ulimit 。。。
您需要登录后才可以回帖 登录 | 立即注册

返回顶部