-
Notifications
You must be signed in to change notification settings - Fork 2
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
using a ThreadPoolExecutor to match socket pool #14
Conversation
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.
Nice!
pybase/region/client.py
Outdated
@@ -142,7 +142,6 @@ def _send_request(self, rq, lock_timeout=10): | |||
to_send = pack(">IB", total_length - 4, len(serialized_header)) | |||
to_send += serialized_header + rpc_length_bytes + serialized_rpc | |||
|
|||
pool_id = my_id % self.pool_size | |||
try: | |||
# todo: quick hack to patch a deadlock happening here. Needs revisiting. | |||
with acquire_timeout(self.write_lock_pool[pool_id], lock_timeout) as acquired: |
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.
There's still a reference to the write_lock_pool
here
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.
aaah, I'll get rid of that
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.
its gone
pybase/region/client.py
Outdated
sp = thread_name.split("_") # i.e. splitting "ThreadPoolExecutor-1_0" | ||
pool_id = int(sp[1]) # thread number is now responsible for only using its matching socket | ||
|
||
client.sock_pool[pool_id].send(to_send) |
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.
Should we move the send
into the try
below to be able use the same exception handling?
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.
yes
Instead of making multiple locks between sending and receiving insanity... why not just have a ThreadPoolExecutor with a number of threads equal to the socket pool size. Then users of the Client can simply submit work, and open thread in the ThreadPool will simply do the work. Each thread in a ThreadPoolExecutor has a unique number (say
ThreadPoolExecutor-1_0
where the last number is the thread number. Simply use that number to decide which socket to use, and voilà, no more contention for a socket.I'll test this Monday.