-
-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows have EMFILE: too many open files problem #2604
Comments
I'm using a little trick for fix this at moment the build folder include all my archive articles about 4000 pages and 7000 images. const yargs = require('yargs/yargs');
const copy = require('recursive-copy');
module.exports = (eleventyConfig) => {
eleventyConfig.setUseGitIgnore(false);
const argv = yargs(process.argv).argv;
if (argv.input == 'src') {
eleventyConfig.addPassthroughCopy(`${argv.input}/images`);
eleventyConfig.addPassthroughCopy(`${argv.input}/spotlight/**/*.jpg`);
eleventyConfig.addPassthroughCopy(`${argv.input}/english/spotlight/**/*.jpg`);
}
if (argv.input == 'build') {
copy(`${argv.input}/images`, '_site/images', { overwrite: true });
copy(`${argv.input}/spotlight`, '_site/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
copy(`${argv.input}/english/spotlight`, '_site/english/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
}
} |
Related: #2139 |
I tried use seem like when I use |
@ausir0726 And you get this error consistently? https://www.11ty.dev/docs/copy/ says that Eleventy uses the It looks like the current passthrough copy defaults are defined in: eleventy/src/TemplatePassthrough.js Lines 194 to 207 in 631c881
Scrolling through https://github.com/timkendrick/recursive-copy#usage options, there is a potentially interesting option called eleventyConfig.addPassthroughCopy(`${argv.input}/images`, { concurrency: 100 }); |
@pdehaan seems like
[11ty] Copied 7883 files / Wrote 2167 files in 343.59 seconds (158.6ms each, v2.0.0-canary.16)
[11ty] Copied 7883 files / Wrote 2167 files in 333.78 seconds (154.0ms each, v2.0.0-canary.16)
[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble rendering pug template ./build/scripts/vender.js.pug (via TemplateContentRenderError)
[11ty] 2. Having trouble compiling template ./build/scripts/vender.js.pug (via TemplateContentCompileError)
[11ty] 3. EMFILE: too many open files, open 'node_modules\alpinejs\dist\cdn.js'
[11ty] at ./build/scripts/vender.js.pug line 2 (via Error)
[11ty]
[11ty] Original error stack trace: Error: EMFILE: too many open files, open 'node_modules\alpinejs\dist\cdn.js'
[11ty] at ./build/scripts/vender.js.pug line 2
[11ty] at Object.openSync (node:fs:594:3)
[11ty] at Object.readFileSync (node:fs:462:35)
[11ty] at Function.read (C:\Users\ausir\proj\ntu\node_modules\pug-load\index.js:85:13)
[11ty] at Object.read (C:\Users\ausir\proj\ntu\node_modules\pug\lib\index.js:164:25)
[11ty] at C:\Users\ausir\proj\ntu\node_modules\pug-load\index.js:28:25
[11ty] at walkAST (C:\Users\ausir\proj\ntu\node_modules\pug-walk\index.js:26:18)
[11ty] at C:\Users\ausir\proj\ntu\node_modules\pug-walk\index.js:112:20
[11ty] at Array.reduce (<anonymous>)
[11ty] at walkAndMergeNodes (C:\Users\ausir\proj\ntu\node_modules\pug-walk\index.js:111:18)
[11ty] at walkAST (C:\Users\ausir\proj\ntu\node_modules\pug-walk\index.js:40:19)
[11ty] Wrote 0 files in 10.36 seconds (v2.0.0-canary.16)
error Command failed with exit code 1. by the way, when I use following code if (argv.input == 'build') {
console.time('a');
console.time('b');
console.time('c');
copy(`${argv.input}/images`, '_site/images', { overwrite: true }).then(() => { console.timeEnd('a'); });
copy(`${argv.input}/spotlight`, '_site/spotlight', { overwrite: true, filter: ['**/*.jpg'] }).then(() => { console.timeEnd('b'); });
copy(`${argv.input}/english/spotlight`, '_site/english/spotlight', { overwrite: true, filter: ['**/*.jpg'] }).then(() => { console.timeEnd('c'); });
} I got the result a: 592.59ms
c: 2.621s
[11ty] Wrote 2167 files in 192.89 seconds (89.0ms each, v2.0.0-canary.16)
b: 3:14.173 (m:ss.mmm) |
I have a profermance question about echo %time% && merge-dirs src build && merge-dirs archive build && echo %time% result 14:06:10.27
14:06:10.27 it's same copy 7800 images to build folder, build only use 1s. is |
Unfortunately |
a: 592.59ms # `${argv.input}/images/**`
b: 3:14.173 (m:ss.mmm) # `${argv.input}/spotlight/**/*.jpg`
c: 2.621s # `${argv.input}/english/spotlight/**/*.jpg`
[11ty] Wrote 2167 files in 192.89 seconds (89.0ms each, v2.0.0-canary.16) Where 193 second build time is 3.2 minutes or 3m:13s. But still, 7800 image is a lot of images, and file i/o operations. It might be worth filing an issue in the From the
Interesting that they have a default https://www.11ty.dev/docs/debug-performance/#show-all-performance-measurements has a good section on benchmarking and if you run something like set DEBUG=Eleventy:Benchmark* & npx @11ty/eleventy it should show you aggregate benchmark data for passthrough copy. I guess my next questions would be, if you don't do any image/asset copying and just build your pages, how long is the build time for the site? Does it still take 190s to write the 2,167 files? |
Looking at
As close as I can figure, I'd need to look a bit closer at your |
OK, a bit of weekend comedy: # Duplicate "./assets/screenshot1.png" about 8000x, for about 5.6 GB of wasted hard drive space.
for i in {2..8000}; do cp screenshot1.png "screeshot$i.png"; done ls -lh assets/ | tail -10
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot990.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot991.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot992.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot993.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot994.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot995.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot996.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot997.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot998.png
-rw-r--r--@ 1 pdehaan wheel 738K 15 Oct 08:45 screeshot999.png du -sh assets # 5.6G assets If I manually call
If I use passthrough copy, it copies 8002 files (and builds the 6 trivial pages) in 5.3s: [11ty] Writing www/index.html from ./src/index.liquid
[11ty] Writing www/pages/one/index.html from ./src/pages/one.liquid
[11ty] Writing www/pages/two/index.html from ./src/pages/two.liquid
[11ty] Writing www/pages/three/index.html from ./src/pages/three.liquid
[11ty] Writing www/pages/four/index.html from ./src/pages/four.liquid
[11ty] Writing www/pages/five/index.html from ./src/pages/five.liquid
[11ty] Copied 8002 files / Wrote 6 files in 5.34 seconds (v2.0.0-canary.16) const copy = require('recursive-copy');
/**
* @typedef {import('@11ty/eleventy/src/UserConfig')} EleventyConfig
* @typedef {ReturnType<import('@11ty/eleventy/src/defaultConfig')>} EleventyReturnValue
* @type {(eleventyConfig: EleventyConfig) => EleventyReturnValue}
*/
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("assets")//, {overwrite: false, concurrency: 50});
// console.time("asset-copy");
// copy('assets', 'www/assets', {overwrite: true}, function(err, results) {
// console.timeEnd("asset-copy");
// if (err) {
// console.error(`[ERROR] Copy failed: ${err.message}`);
// } else {
// console.info(`Copied ${results.length} files`);
// }
// });
return {
dir: {
input: "src",
output: "www",
}
};
}; Not sure how deeply nested your file structure is (mine is all just flat assets/*.png at the same depth).
const mergedirs = require('merge-dirs').default;
mergedirs('assets', 'www/assets')//, 'skip'); rm -rf www
npm run build
> [email protected] build
> time eleventy
[11ty] Writing www/pages/five/index.html from ./src/pages/five.liquid
[11ty] Writing www/pages/four/index.html from ./src/pages/four.liquid
[11ty] Writing www/index.html from ./src/index.liquid
[11ty] Writing www/pages/three/index.html from ./src/pages/three.liquid
[11ty] Writing www/pages/two/index.html from ./src/pages/two.liquid
[11ty] Writing www/pages/one/index.html from ./src/pages/one.liquid
[11ty] Wrote 6 files in 0.02 seconds (v2.0.0-canary.16)
real 0m5.771s
user 0m0.430s
sys 0m2.542s Then subsequent npm run build calls are much faster: ...
www/assets/screeshot997.png exists, skipping...
www/assets/screeshot998.png exists, skipping...
www/assets/screeshot999.png exists, skipping...
[11ty] Writing www/pages/five/index.html from ./src/pages/five.liquid
[11ty] Writing www/pages/one/index.html from ./src/pages/one.liquid
[11ty] Writing www/pages/three/index.html from ./src/pages/three.liquid
[11ty] Writing www/pages/two/index.html from ./src/pages/two.liquid
[11ty] Writing www/pages/four/index.html from ./src/pages/four.liquid
[11ty] Writing www/index.html from ./src/index.liquid
[11ty] Wrote 6 files in 0.02 seconds (v2.0.0-canary.16)
real 0m0.255s
user 0m0.245s
sys 0m0.063s So 5.77s on a fresh build without a ./www/ output folder, but only 0.25s on subsequent builds where it floods my terminal w/ "${file} exists, skipping..." output. |
Dear @pdehaan my archive folder structure
even use my 2015 MBP with SSD , build site need 336.91 seconds also (copied 7883 files , wrote 2168 files) and I got build fail when I decrase concurrency to 50 , build success set DEBUG=Eleventy:Benchmark* & npx eleventy --input=build
Eleventy:Benchmark Benchmark 852ms 0% 4× (Aggregate) Searching the file system +0ms
Eleventy:Benchmark Benchmark 4103ms 1% 6502× (Aggregate) Template Read +2ms
Eleventy:Benchmark Benchmark 419783ms 99% 7883× (Aggregate) Passthrough Copy File +1ms
Eleventy:Benchmark Benchmark 0ms 0% 4336× (Aggregate) (count) getOutputHref +1ms
Eleventy:Benchmark Benchmark 0ms 0% 4336× (Aggregate) (count) getOutputPath +0ms
Eleventy:Benchmark Benchmark 0ms 0% 4336× (Aggregate) (count) Render Permalink +1ms
Eleventy:Benchmark Benchmark 364394ms 86% 10818× (Aggregate) Template Compile +1ms
Eleventy:Benchmark Benchmark 51ms 0% 3× (Aggregate) > Compile > ./build/scripts/vender.js.pug +1ms
Eleventy:Benchmark Benchmark 521ms 0% 6484× (Aggregate) Render +0ms
...
Eleventy:Benchmark Benchmark 407853ms 96% 2168× (Aggregate) Template Write +0ms
Eleventy:Benchmark Benchmark 81208ms 19% 2157× (Aggregate) > Compile > ./build/_layouts/spotlight/article.pug +1ms
Eleventy:Benchmark Benchmark 877ms 0% 2× (Aggregate) > Compile > ./build/_layouts/about/about.pug +1ms
Eleventy:Benchmark Benchmark 722ms 0% 1× (Aggregate) > Compile > ./build/_layouts/administration/administration.pug +1ms
Eleventy:Benchmark Benchmark 716ms 0% 2× (Aggregate) > Compile > ./build/_layouts/index.pug +0ms
Eleventy:Benchmark Benchmark 227ms 0% 5× (Aggregate) > Compile > ./build/_layouts/spotlight/spotlight.pug +1ms
Eleventy:Benchmark Benchmark 275228ms 65% 2167× (Aggregate) > Compile > ./build/_layouts/default.pug +1ms
[11ty] Copied 7883 files / Wrote 2168 files in 425.59 seconds (196.3ms each, v2.0.0-canary.16) |
What's your build time if you do NO passthrough copy (or manual asset copying using It seems odd that a build takes 425s and passthrough copy is taking roughly 420s; plus:
If removing Eleventy passthrough copy solves 99% of the performance issues, I'd say switch to another option ( But now I'm curious how quickly my relatively new [corporate] 2021 Apple M1 Max laptop could compile the site. |
If I remove passthrough copy each article have 2 layers layout seems like copy 7000 images need another 200s. $ set DEBUG=Eleventy:Benchmark* & npx eleventy --input=build
Eleventy:Benchmark Benchmark 65ms 0% 2× (Aggregate) Searching the file system +0ms
Eleventy:Benchmark Benchmark 1365ms 1% 6502× (Aggregate) Template Read +3ms
Eleventy:Benchmark Benchmark 0ms 0% 4336× (Aggregate) (count) getOutputHref +1ms
Eleventy:Benchmark Benchmark 0ms 0% 4336× (Aggregate) (count) getOutputPath +0ms
Eleventy:Benchmark Benchmark 0ms 0% 4336× (Aggregate) (count) Render Permalink +1ms
Eleventy:Benchmark Benchmark 180363ms 93% 10818× (Aggregate) Template Compile +1ms
Eleventy:Benchmark Benchmark 153ms 0% 3× (Aggregate) > Compile > ./build/scripts/vender.js.pug +0ms
Eleventy:Benchmark Benchmark 498ms 0% 6484× (Aggregate) Render +1ms
...
...
Eleventy:Benchmark Benchmark 185281ms 95% 2168× (Aggregate) Template Write +1ms
Eleventy:Benchmark Benchmark 39725ms 20% 2157× (Aggregate) > Compile > ./build/_layouts/spotlight/article.pug +0ms
Eleventy:Benchmark Benchmark 438ms 0% 5× (Aggregate) > Compile > ./build/_layouts/spotlight/spotlight.pug +2ms
Eleventy:Benchmark Benchmark 419ms 0% 2× (Aggregate) > Compile > ./build/_layouts/index.pug +1ms
Eleventy:Benchmark Benchmark 150ms 0% 1× (Aggregate) > Compile > ./build/_layouts/administration/administration.pug +0ms
Eleventy:Benchmark Benchmark 147ms 0% 2× (Aggregate) > Compile > ./build/_layouts/about/about.pug +1ms
Eleventy:Benchmark Benchmark 135430ms 69% 2167× (Aggregate) > Compile > ./build/_layouts/default.pug +1ms
[11ty] Wrote 2168 files in 197.72 seconds (91.2ms each, v2.0.0-canary.16) |
Awesome, thanks!
Somewhat surprising is that you're spending 135+40 = 175 seconds in your layout files (89% of your build time?). |
Seems like pug is slow than other template language but EMFILE error on windows is really troubled us... |
I tried use
const copy = require('recursive-copy');
const start = async () => {
console.time('recursive-copy');
const copied = await copy(`build/spotlight`, '_site/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
console.timeEnd('recursive-copy');
console.log(`${copied.length} files copied`);
};
start(); result node benchmak.js
recursive-copy: 3.674s
6080 files copied don't undersatnd why copy 7000 files in 11ty need 400s? |
like the test before,
seems like render pages and copy files at same time. |
If Although, your ~4 second benchmark might prove that it's better to use I'd also probably try putting the asset copy code in the eleventyConfig.on("eleventy.after", function (args) {
// Copy files in this event?
const outputDir = args.dir.output;
console.log({outputDir}); // `{ outputDir: "www" }`
// console.log("\n\n", {args}, "\n\n");
}); If my theory is right, that a: 592.59ms # `${argv.input}/images/**`
b: 3:14.173 (m:ss.mmm) # `${argv.input}/spotlight/**/*.jpg`
c: 2.621s # `${argv.input}/english/spotlight/**/*.jpg` Although, remember that if you're doing copies on 3 folders w/ default 255 concurrency, that's potentially 765 files that the OS is trying to copy simultaneously. |
I can't use as my test option 1 : use concurrency 50 module.exports = (eleventyConfig) => {
const argv = yargs(process.argv).argv;
eleventyConfig.addPassthroughCopy(`${argv.input}/images`, { concurrency: 50 });
eleventyConfig.addPassthroughCopy(`${argv.input}/spotlight/**/*.jpg`, { concurrency: 50 });
eleventyConfig.addPassthroughCopy(`${argv.input}/english/spotlight/**/*.jpg`, { concurrency: 50 });
... result total used time : option 2 : use const copy = require('recursive-copy');
module.exports = (eleventyConfig) => {
eleventyConfig.setUseGitIgnore(false);
const argv = yargs(process.argv).argv;
if (argv.input == 'src') {
eleventyConfig.addPassthroughCopy(`${argv.input}/images`);
eleventyConfig.addPassthroughCopy(`${argv.input}/spotlight/**/*.jpg`);
eleventyConfig.addPassthroughCopy(`${argv.input}/english/spotlight/**/*.jpg`);
}
if (argv.input == 'build') {
copy(`${argv.input}/images`, '_site/images', { overwrite: true });
copy(`${argv.input}/spotlight`, '_site/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
copy(`${argv.input}/english/spotlight`, '_site/english/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
}
... result total used time : option 3 : use const copy = require('recursive-copy');
module.exports = (eleventyConfig) => {
eleventyConfig.setUseGitIgnore(false);
const argv = yargs(process.argv).argv;
eleventyConfig.on("eleventy.after", function (args) {
copy(`${argv.input}/images`, '_site/images', { overwrite: true });
copy(`${argv.input}/spotlight`, '_site/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
copy(`${argv.input}/english/spotlight`, '_site/english/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
}); result total used time : seems like bottleneck is I will use the option 2 for fix this problem for now. thanks. |
I think the simplest explanation is that you're trying to concurrently (1) read → (2) compile → (3) render → (4) write 2,167 *.pug files (plus calculating all the data cascade and collections, etc) while also simultaneously copying 7,883 image assets (in potentially [deeply] nested folders which need to be created before passthrough copying). Although I'm not sure why your if (argv.input == 'build') {
copy(`${argv.input}/images`, '_site/images', { overwrite: true });
copy(`${argv.input}/spotlight`, '_site/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
copy(`${argv.input}/english/spotlight`, '_site/english/spotlight', { overwrite: true, filter: ['**/*.jpg'] });
} solution is faster than doing it in an |
@pdehaan I think |
Describe the bug
When I use 11ty develope my site it's work very well.
but when I put all my archive articles and image to 11ty and build it
it's have EMFILE: too many open files error
it's total about 7000 iamges and 4000 pages (each page have 2 layer layout with pug )
( image copy done, pug complier done, but write html fail )
I tried disable addPassthroughCopy my images, and it's work fine.
seems like addPassthroughCopy and write html will reach the open files limit at same time.
It's only happen on windows ( win10 pro installed WSL 2 docker)
To Reproduce
eleventy --input=build
Expected behavior
build success, but fail.
Screenshots
Environment:
Additional context
it's work fine on linux and mac.
The text was updated successfully, but these errors were encountered: