-
Notifications
You must be signed in to change notification settings - Fork 86
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
Sharing sockets between multiprocess workers with Socket Manager #25
Conversation
First of all, this is great achievement. Good job! |
module ServerEngine | ||
module SocketManager | ||
|
||
def self.new_socket_manager |
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.
looks like this method is not complete yet.
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 fixed it now.
It looks easy but it was a little confusing.
Firstly I thought I I have to use OptionParser not using ARGV[-1].
But if I use OptionParser here, in fluentd side it is also used, I have to set all option in both side not to cause OptionParser::InvalidOption. it is bored.
Then, secondly I thought I have to create interface class of command parser and use this interface in fluentd side. like this
opt_parser = ServerEngine::OptParser.new
But I did't want to oblige users to do like above because it is too bored and not cool.
Then at last, I used ENV unwillingly.
If I should do in other way, I'll do.
Thank you very much! I love fluentd and I'm very glad to be able to get involved this project! Firstly the API to use Socket manager is here. #get socket manager in a spawned worker
socket_manager = ServerEngine::SocketManager.new_socket_manager Then from this Socket Manager, users can create TCP or UDP sockets in spawned worker like this. #get FD from socket manager
fd = socket_manager.get_tcp(bind, port)
#create listen socket from FD
lsock = TCPServer.for_fd(fd.to_i) I implemented the API in Socket Manager class, |
@naritta thank you. how does parent process create SocketManager::Server? how does child process get UNIX socket? |
I think that there is a race condition in fundamental design. Do you consider this scenario?:
This rarely happens but its impact is significant if it happens. |
Thank you. How parent process create SocketManager::Server and child process get UNIX socket is below.
|
For the race condition problem between processes, I fixed the design to use different Unix Socket for every processes. the problem between processes should be solved by this change and I think another problem in a processes (with various plugins) will not happen because in one process it creates socket synchronously in order. (For example, assuming setting in_forward and in_http, race condition will not happen between in_forward and in_http in same one process.) |
77532be
to
96c2122
Compare
Would you mind if you continue development based on https://github.com/fluent/serverengine/tree/socket-manager-api branch? It is based on your #26 branch, and implements SocketManager as a stand-alone library which isn't tightly coupled with ProcessManager. As the commit message explains (d7c632c), it doesn't use DRb. And it creates socket (or named pipe) pair for each requests. So it simplifies following issues I was going to mention:
I confirmed that above branch can complete simple test cases I added. But I have not tried Windows implementation. And as you can see TODO comments, its implementation is not completely working code yet (so CI on AppVeyor doesn't pass). So I would like to rely on you to improve the Windows support. With MultiSpawnServer (for fluentd, maybe), you can create SocketManager::Server and set socket path ( |
I got it. Thank you for the reviewing! |
@naritta If you're struggling to wrap a socket handle in a TCPServer or UDPSocket, you may try to call the other way is also available that extracts SOCKET from a TCPServer or UDPSocket ( |
Thank you very much for teaching me! |
This is a PR for implementation of this issue.
Sharing sockets between multiprocess workers #24
Details is here.
http://qiita.com/ritta/items/d1ca662cdd04c54dba2c