Skip to content

Commit

Permalink
limit rendering concurrency to 50 to reduce memory usages.
Browse files Browse the repository at this point in the history
hexo core will use this feature after merge https://github.com/dailyrandomphoto/hexo/commits/limit-rendering-concurrency branch.
  • Loading branch information
dailyrandomphoto committed Oct 17, 2019
1 parent 864dcb5 commit 5d7020e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ huge_site_plugin:
enable: true
concurrency: 10
database_format: 'v8se'
overrideRenderPostFilter: true
```

- `enable` `<String>`
- `enable` `<Boolean>` Enable hexo-huge_site_plugin. Default value is `false`.
- `concurrency` `<Number>` Maximum number of files to be generated in parallel. Default value is `10`. [`hexo generate` options](https://hexo.io/docs/commands#generate)
- Set a small number or provide `-c` option on `generate` command if rendering HTML takes very long time or fails with OOM error.
- `database_format` `<String>` Default value is `v8se`.
- `json` Save the database to file using JSON stringify. Default implementation.
- `v8se` Save the database to file using v8 serialization.
- Set as `v8se` if save database fails.
- `overrideRenderPostFilter` `Boolean` Limit rendering concurrency to reduce memory usages. Default value is `false`.
- Enable it if rendering post takes very long time or fails with OOM error.

## License
Copyright (c) 2019 dailyrandomphoto. Licensed under the [MIT license][license-url].
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const {
toJSON,
convert
} = require('./lib/database');
const registerFilters = require('./lib/filter');

const log = hexo.log;

const config = Object.assign({
enable: false,
database_format: 'v8se',
concurrency: 10
concurrency: 10,
// after merge https://github.com/dailyrandomphoto/hexo/tree/limit-rendering-concurrency branch, remove this
overrideRenderPostFilter: false
}, hexo.config.huge_site_plugin);

/**
Expand Down Expand Up @@ -76,4 +79,7 @@ if (config.enable) {
log.debug('config %s', chalk.magenta(JSON.stringify(config)));
concurrency();
overrideDatabase();
if (config.overrideRenderPostFilter) {
registerFilters(hexo);
}
}
8 changes: 8 additions & 0 deletions lib/filter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = ctx => {
const { filter } = ctx.extend;

filter.unregister('before_generate', require('hexo/lib/plugins/filter/before_generate/render_post')); // eslint-disable-line node/no-missing-require,node/no-extraneous-require
filter.register('before_generate', require('./render_post'));
};
24 changes: 24 additions & 0 deletions lib/filter/render_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const Promise = require('bluebird'); // eslint-disable-line node/no-missing-require,node/no-extraneous-require
const concurrency = 50;

function renderPostFilter(data) {
const renderPosts = model => {
const posts = model.toArray().filter(post => post.content == null);

return Promise.map(posts, post => {
post.content = post._content;
post.site = {data};

return this.post.render(post.full_source, post).then(() => post.save());
}, {concurrency: concurrency});
};

return Promise.all([
renderPosts(this.model('Post')),
renderPosts(this.model('Page'))
]);
}

module.exports = renderPostFilter;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-huge-site-plugin",
"version": "0.0.3",
"version": "0.0.4",
"description": "This plugin helps hexo to generate a huge site.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 5d7020e

Please sign in to comment.