-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
node.js cluster, workers stdouts overlay each other on some hosts #12724
Comments
FWIW v0.10.x and v0.12.x are no longer supported. |
If you're using Node 0.10.47, 0.10.48, and 0.12.7 then you're going to need to update. Those release lines are EOL |
Just tried to use v6.3.0 and v7.9.0 But the main issue is why on host1 and host2 the code always works good, but on host3 it always fails |
So you have multiple cluster worker processes reading files at the same time and sending the output to the same place? I think it's expected that things could be interleaved. |
If it would be a multi threaded C++ program I would expect interleaving because it have no locking from the box. But from the node documentation I see that cluster workers send their output to parent and parent synchronously writes it to file or console (page describing api 'process'). So I expect no interleaving in node. If no interleaving on host1 and host2 is some unexpected side behaviour than give me please some hints how to do my task with node correct way |
They do not do that. The data reading and writing your cluster workers are doing are happening in completley independent threads (EDIT: I mean processes, which are more independent than threads), there is no synchronization. What docs did you see that makes you think cluster workers do I/O thorugh their parent? var cluster = require("cluster");
var fs = require("fs");
var workerId = cluster.worker && cluster.worker.id || 1;
var stream = fs.createReadStream("./data" + workerId + ".log");
stream.on("end", function () {
process.exit();
});
stream.pipe(process.stdout); This cluster code is the equivalent of The code has several problems:
|
You should output to separate files. |
|
I found solution var cluster = require("cluster");
cluster.setupMaster({
exec: "./worker.js",
=> silent: true
});
for (var i = 0; i < 2; i++) {
var worker = cluster.fork();
=> worker.process.stdout.pipe(process.stdout);
=> worker.process.stderr.pipe(process.stderr);
} I think the reason for such differences in the behaviour of the same code on different versions of ubuntu is in the linux kernel file handle buffer implementations. |
Linux host-1-ok 4.4.0-62-generic Improving code readability on lib/_http_agent.js #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux "Ubuntu 16.04.2 LTS"
Linux host-2-ok 4.4.0-42-generic extending options from a prototype #62-Ubuntu SMP Fri Oct 7 23:11:45 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux "Ubuntu 16.04.1 LTS"
Linux host-3-fail 3.13.0-116-generic io.js TC Meeting 2014-12-17 #163-Ubuntu SMP Fri Mar 31 14:13:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux "Ubuntu 14.04.5 LTS"
Hi. I've encountered very strange behaviour while redirecting workers stdout to file.
On hosts host-1-ok and host-2-ok my code works always as expected but on host host-3-fail the stdout streams from workers overlay each other.
I cannot understand why and what I can do to fix this problem on host-3-fail. Even if my issue is not a core bug please help me to gain an understanding of what is going on and how to solve this problem.
The problem details are here:
http://stackoverflow.com/questions/43663065/node-js-cluster-redirecting-the-childs-stdout-to-file-breaks-data
The text was updated successfully, but these errors were encountered: