-
Notifications
You must be signed in to change notification settings - Fork 64
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
TCPTransport: switch from select.select() to selectors #81
Open
gbanasiak
wants to merge
13
commits into
thespianpy:master
Choose a base branch
from
gbanasiak:selectors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
11fac08
Ignore venv, envrc and pyenv files
gbanasiak ae3cabe
Switch from select.select() to selectors
gbanasiak 3758154
Add socketstress example
gbanasiak b81b5ef
Fix exception type in socketstress
gbanasiak c4350ca
Reduce selector initializations
gbanasiak 588ffe3
Send more messages in socketstress
gbanasiak 0ce97f4
Parametrize repetitions in socketstress
gbanasiak 992a718
Send completion only once
gbanasiak aaab707
Revert "Reduce selector initializations"
gbanasiak 5a3e011
socketstress: Wait until workers really started
gbanasiak e81b06b
Backoff on ENOTCONN error
gbanasiak ae99b36
Modify comment
gbanasiak 13b0810
Modify another comment
gbanasiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Measures the time required to send and receive to/from | ||
# a given number of actors with the intention to | ||
# compare efficiency of different I/O multiplexing | ||
# methods. | ||
# | ||
# Run this from the top level as: | ||
# $ python examples/socketstress.py [<number-of-workers>] [<number-of-repetitions>] | ||
|
||
|
||
import logging | ||
import time | ||
from logsetup import logcfg | ||
from datetime import timedelta | ||
from thespian.actors import * | ||
|
||
### messages | ||
|
||
class BaseMsg(object): pass | ||
|
||
|
||
class Ping(BaseMsg): pass | ||
|
||
|
||
class Pong(BaseMsg): pass | ||
|
||
|
||
class Run(BaseMsg): pass | ||
|
||
|
||
class Start(BaseMsg): | ||
def __init__(self, num_workers, num_repetitions): | ||
self.num_workers = num_workers | ||
self.num_repetitions = num_repetitions | ||
|
||
|
||
class WorkerStart(BaseMsg): pass | ||
|
||
|
||
class WorkerStarted(BaseMsg): pass | ||
|
||
### actors | ||
|
||
class Dispatcher(ActorTypeDispatcher): | ||
def __init__(self): | ||
self.num_workers = 0 | ||
self.workers = [] | ||
self.pong_count = 0 | ||
self.worker_started_count = 0 | ||
self.sender = None | ||
self.has_completed = False | ||
|
||
def receiveMsg_Start(self, message, sender): | ||
self.num_workers = message.num_workers | ||
self.num_repetitions = message.num_repetitions | ||
self.sender = sender | ||
logging.info('receiveMsg_Start(): creating %s workers...', self.num_workers) | ||
for _ in range(self.num_workers): | ||
worker = self.createActor(Worker) | ||
self.workers.append(worker) | ||
self.send(worker, WorkerStart()) | ||
logging.info('receiveMsg_Start(): done', self.num_workers) | ||
|
||
def receiveMsg_Run(self, message, sender): | ||
logging.info('receiveMsg_Run(): sending pings...') | ||
self.sender = sender | ||
for each in self.workers: | ||
self.send(each, Ping()) | ||
logging.info('receiveMsg_Run(): done') | ||
|
||
def receiveMsg_Pong(self, message, sender): | ||
self.pong_count += 1 | ||
if self.pong_count >= self.num_workers * self.num_repetitions and not self.has_completed: | ||
self.has_completed = True | ||
self.send(self.sender, "done") | ||
if self.num_repetitions > 1: | ||
self.send(sender, Ping()) | ||
|
||
def receiveMsg_WorkerStarted(self, message, sender): | ||
self.worker_started_count += 1 | ||
if self.worker_started_count == self.num_workers: | ||
logging.info('receiveMsg_WorkerStarted(): %s workers started', self.worker_started_count) | ||
self.send(self.sender, "started") | ||
|
||
|
||
class Worker(ActorTypeDispatcher): | ||
def receiveMsg_Ping(self, message, sender): | ||
self.send(sender, Pong()) | ||
|
||
def receiveMsg_WorkerStart(self, message, sender): | ||
self.send(sender, WorkerStarted()) | ||
|
||
|
||
def run_example(num_workers, num_repetitions): | ||
try: | ||
num_workers = int(num_workers) | ||
num_repetitions = int(num_repetitions) | ||
except ValueError: | ||
print('usage: socketstress.py [<num-workers>] [<num-repetitions>]') | ||
sys.exit(1) | ||
asys = ActorSystem("multiprocTCPBase", logDefs=logcfg) | ||
try: | ||
print(f'socketstress with {num_workers} worker(s) and {num_repetitions} repetition(s)') | ||
print('creating dispatcher...') | ||
dispatcher = ActorSystem().createActor(Dispatcher) | ||
print('starting workers...') | ||
ActorSystem().ask(dispatcher, Start(num_workers, num_repetitions)) | ||
print('run!') | ||
start = time.perf_counter() | ||
ActorSystem().ask(dispatcher, Run()) | ||
end = time.perf_counter() | ||
print(f'run completed in {end - start} seconds') | ||
finally: | ||
asys.shutdown() | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
run_example( | ||
sys.argv[1] if len(sys.argv) > 1 else "3", | ||
sys.argv[2] if len(sys.argv) > 2 else "1" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Required to pass
thespian/test/test_generators.py
test on MacOS.selectors
signal socket as ready to send yet[Errno 57] Socket is not connected
error is raised when sending in_next_XMIT_2()
. After a slight backoff, all works fine. From what I could tell looking at packet dumps,socket.send()
was throwing this error after TCP connection was already established. What is special about this test is the use of global names combined with creation of multiple actors in quick succession.Fun fact: This test was created after report from Rally lead developer in March 2017. Rally no longer uses global names. They were removed from Rally by Thespian lead developer in December 2017. :-)