Skip to content
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

Merged
merged 8 commits into from
May 24, 2023

Conversation

zacharyp
Copy link

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.

@zacharyp zacharyp changed the title using a ThreadPoolExecutor with matching number of works to socket po… using a ThreadPoolExecutor to match socket pool May 19, 2023
@zacharyp zacharyp requested a review from mcvlad May 19, 2023 23:33
Copy link
Member

@stevefranks stevefranks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -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:
Copy link
Member

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

Copy link
Author

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its gone

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)
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@zacharyp zacharyp merged commit 58cf1e1 into master May 24, 2023
@zacharyp zacharyp deleted the zpitts/FL-32990-using-ThreadPoolExecutor branch May 24, 2023 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants