-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Create cluster.cr #3672
Create cluster.cr #3672
Conversation
Add a Cluster-like capacity to Crystal
(ENV["FORKED"] ||= "0") == "1" | ||
end | ||
|
||
def self.getEnv (env : String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is unneccesary
class Cluster | ||
|
||
def self.fork (env : Hash) | ||
env["FORKED"] = "1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would namespace this env var more.
I would like to see a forking cluster helper in the standard library, however I'm a little dubious on the API. At the very least needs a format and docs. |
Why not take inspiration from the nodejs Cluster api? https://nodejs.org/docs/latest/api/cluster.html |
return Process.fork { Process.run(PROGRAM_NAME, nil, env, true, false, true, true, true, nil ) } | ||
end | ||
|
||
def self.isMaster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.master?
is more Crystal/Ruby semantic. Same for self.slave?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I mention the NodeJS Cluster API, I speak about the API, not the semantic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeJS API adheres to JS conventions, not to Ruby ones. It's a convention to use isFoo
in JS, whereas in Ruby you'd rather write foo?
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, changes done
end | ||
|
||
def self.isMaster | ||
(ENV["FORKED"] ||= "0") == "0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't set value in checker method. Proper way would be (ENV["FORKED"]? || "0") == "0"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Updated semantic
return Process.fork { Process.run(PROGRAM_NAME, nil, env, true, false, true, true, true, nil ) } | ||
end | ||
|
||
def self.master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def self.master?
@adrien-thierry NodeJS cluster comes with more than just wrapping a child process with ENV parameter. Quoting from the docs:
That said, having similar capabilities in Crystal would be great but IMHO this PR in its current form doesn't add much value to stdlib. |
|
||
def self.fork (env : Hash) | ||
env["FORKED"] = "1" | ||
return Process.fork { Process.run(PROGRAM_NAME, nil, env, true, false, true, true, true, nil ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant return
change "slave" by "worker"
@Sija With SO_REUSEPORT support, it's a goot start to add easy multithreading-like capabilities to http server. As is, it lacks events (close etc) and IPC |
Removed redundant return
It's better to see something like this evolve as a separate shard first. I would suggest also to take a look at https://github.com/ysbaddaden/panzer . Thanks! |
Add a Cluster-like capacity to Crystal