cluster: refactor module into multiple files#10746
Conversation
|
I think the triple newlines could be changed to just double newlines (one empty line between function definitions, etc. instead of two). |
jasnell
left a comment
There was a problem hiding this comment.
Generally LGTM. Couple comments tho (consider to be optional)
There was a problem hiding this comment.
While we're at it, perhaps consider eliminating the closure by moving these handlers into top level functions. Doing so should result in at least some performance improvement overall.
There was a problem hiding this comment.
If it was a function, how would it get access to this? Wouldn't it have to be bound, which has perf negatives?
lib/internal/cluster/Worker.js
Outdated
There was a problem hiding this comment.
The deprecation message could be made into a const and reused.
lib/internal/cluster/master.js
Outdated
There was a problem hiding this comment.
Nit: While we're refactoring all this code, maybe remove handle as an argument here? It's not used in the function.
6b9bd1a to
425162e
Compare
|
Switched from two blank lines to one blank line between functions. @mscdex I have two questions for you:
|
|
|
OK, thanks! That's what I was thinking on both points, but wanted to check. |
sam-github
left a comment
There was a problem hiding this comment.
Couple small suggestions, and I don't think we should be using mixed case filenames, but basically LGTM.
There was a problem hiding this comment.
If it was a function, how would it get access to this? Wouldn't it have to be bound, which has perf negatives?
There was a problem hiding this comment.
I find this kindof for construction hard to read, could you put the empty statement, the ;, on the next line?
There was a problem hiding this comment.
file-naming convention in lib/ is is snake_case.js, AFAICT.
There was a problem hiding this comment.
I used https://github.com/nodejs/node/blob/master/lib/internal/streams/BufferList.js as a reference for naming files that hold a single data type.
There was a problem hiding this comment.
I think that BufferList is an unfortunate outlier. lib/internal/streams/lazy_transform.js is a better model to follow.
There was a problem hiding this comment.
I'm all for sorting requires. Do we sort by the variable name on the left hand side, or the string inside of require()? What about internal modules? Should they be grouped differently?
There was a problem hiding this comment.
Lexical sort (in ASCII order/posix "C" locale) on the statements (which ends up being by name of variable, but variable name usually maps 1:1 to the require name, es6 requires aside) (:sort in vim, pipe block through !sort, whatever your editor likes). No grouping, too complicated to document and reproduce.
There was a problem hiding this comment.
Why not use ! operator instead of comparison against false? As is done in
+ if (!(this instanceof Worker))
+ return new Worker(options);
lib/internal/cluster/child.js
Outdated
lib/internal/cluster/master.js
Outdated
There was a problem hiding this comment.
I think a strict comparison against a boolean is faster. This was also the existing code.
There was a problem hiding this comment.
Some of the asserts don't do direct comparisons. but its existing, so NBD. I more noticed the inconsistent usage, sometimes direct comparisons, sometimes not. But again, pre-existing, so its OK.
425162e to
b032fef
Compare
|
New CI: https://ci.nodejs.org/job/node-test-pull-request/5848/ Looks like an unrelated failure, so trying again: https://ci.nodejs.org/job/node-test-pull-request/5850/ |
This commit splits the existing cluster module into several internal modules. More specifically, the cluster master and worker implementations are separated, and the various data structures are separated. PR-URL: nodejs#10746 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
b032fef to
2f885e7
Compare
This commit splits the existing cluster module into several internal modules. More specifically, the cluster master and worker implementations are separated, and the various data structures are separated. PR-URL: nodejs#10746 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit splits the existing cluster module into several internal modules. More specifically, the cluster master and worker implementations are separated, and the various data structures are separated. PR-URL: #10746 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit splits the existing cluster module into several internal modules. More specifically, the cluster master and worker implementations are separated, and the various data structures are separated. PR-URL: nodejs#10746 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit splits the existing cluster module into several internal modules. More specifically, the cluster master and worker implementations are separated, and the various data structures are separated. PR-URL: nodejs#10746 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
|
@nodejs/lts @cjihrig ... trying to decide if we should backport this to v6 or not. Recommending that we skip backporting to v4 |
|
If we do backport to v6, a backport PR will be required. |
I've always found the cluster code unpleasant to deal with. Currently, one large file contains the
Worker,SharedHandle, andRoundRobinHandlestructures. The same file also contains the cluster master and worker implementations, each of which modifiesWorker. This makes the code tricky, because when you jump around in the code, you need to determine what context you're working in. I'm hoping to make it more readable/maintainable.This commit splits the existing cluster module into several internal modules. More specifically, the cluster master and worker implementations are separated, and the various data structures are separated.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
cluster