Skip to content
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

Multicore usage #520

Closed
improvedk opened this issue Mar 9, 2014 · 6 comments
Closed

Multicore usage #520

improvedk opened this issue Mar 9, 2014 · 6 comments

Comments

@improvedk
Copy link

Processing ~300 posts takes almost a minute, which is workable, but I'd like it to be much faster.

Looking at the task manager I see 13 node.exe processes (I've got 12 cores). 12 processes running hexo\lib\plugins\console\generate\worker.js, but doing nothing. And then a single process running hexo\bin\hexo g using 100% of the single core.

Am I missing something, or shouldn't hexo be able to utilize those other cores? multi_thread is set to true in my _config.yml, but I'm not sure if it's relevant.

@tommy351
Copy link
Member

tommy351 commented Mar 9, 2014

What multi_thread setting actually do is only writing files. Post rendering tasks are done in main process.

Because Node.js is single thread, I have to create a new Hexo instance if I want to move post rendering tasks to workers.

I wonder if there's a better way to handle this problem.

@improvedk
Copy link
Author

I see - thanks for clarifying. Unfortunately my Node.js experience is limited to just a couple of Hexo plugins, as part of migrating my blog here. While the 1 min compile time is OK for now, I'll probably take a stab at it and see if I can figure out a way to distribute the work :)

@improvedk
Copy link
Author

Tested a bit more. Loading & processing all the source posts (240) takes 7 seconds. Subsequently, 40 seconds is used on actually rendering the posts. Running process monitor I can see that all of the layouts files are loaded again and again, probably once per source post. Since all files are in memory (by the OS), CPU is the only bottleneck - but at least it narrows the bottleneck down to running the actual EJS templates, rather than processing the posts themselves.

@tommy351
Copy link
Member

Maybe we can try to rewrite the theme with other template engines and see if this can make the rendering faster.

@improvedk
Copy link
Author

I actually rather like the use of EJS and I think the performance is decent - so I'd much rather come up with a solution to distributing it over multiple processes. As I have 12 cores and only one is used, that'd bring the processing time down from 7+40 seconds to just 7+3 seconds, which is definitely OK.

Right now I'm working around this by just doing a generate and then running the debug server which updates on-demand, so at this point it's bit of a luxury problem, but still, interesting none the less :)

I'm not at my normal machine right now, so I can't check, but doesn't db.json store all of the posts, categories, tags, etc? What if the main process read & processed the files as it does today, wrote it all to db.json and then spun up a new process, per core, that would simply read the json and then render the posts one by one? The main process could give each post a CPU identifier so each render thread would only render posts meant for CPU 1, 2, 3, etc. Not sure if it's too hack'ish, but I'm not too fluent in Node in regards of what other process-data-sharing options there are available .

@stevenjoezhang
Copy link
Member

Thanks for your feedback. Please join the discussion here: #4355 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants