Conversation
yehonatanz
left a comment
There was a problem hiding this comment.
In addition to previous comments, I'd like to see at least one test dedicated to marine pool.
| return MarinePool(marine_so_path) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session", params=[False, True], ids=["marine", "marine_pool"]) |
There was a problem hiding this comment.
Wouldn't it be more straight forward to pass the fixture names as params and use request.getfixturevalue?
There was a problem hiding this comment.
I don't think so. You add a line and a parameter (request) for each test
There was a problem hiding this comment.
I meant in here, not in every test
marine/marine_pool.py
Outdated
| return [] | ||
|
|
||
| ctx = multiprocessing.get_context("spawn") | ||
| pool = ctx.Pool(self.process_count) |
There was a problem hiding this comment.
Are you spawning a pool each time filter_and_parse is called?
Please don't
marine/marine_pool.py
Outdated
| if len(packets) == 0: | ||
| return [] | ||
|
|
||
| ctx = multiprocessing.get_context("spawn") |
There was a problem hiding this comment.
Why not just use pool = multiprocessing.Pool(count)?
There was a problem hiding this comment.
The default fork_method is "fork" and not "spawn". I assumed @tomlegkov chose spawn for a reason...
There was a problem hiding this comment.
Yeah, he explained it on slack.
Add a comment explaining it so some wise-ass won't change it in the future without understanding.
marine/marine_pool.py
Outdated
| ctx = multiprocessing.get_context("spawn") | ||
| pool = ctx.Pool(self.process_count) | ||
| chunk_size = int(math.ceil(len(packets) / float(self.process_count))) | ||
| packet_chunks = [ |
There was a problem hiding this comment.
multiprocessing.Pool.map already splits the input to batches for you and exposes a clean API.
| @@ -1,4 +1,5 @@ | |||
| from .marine import Marine | |||
| from .marine_pool import MarinePool | |||
There was a problem hiding this comment.
<NotSerious>
MarinePool should be called Lagoon
</NotSerious>
e3de20f to
a53b964
Compare
yehonatanz
left a comment
There was a problem hiding this comment.
I had some notes.
I still think that make init_marine idempotent on the C level (with a is_initialized flag or something) is the best option though.
@tomlegkov What do you think?
marine/marine_pool.py
Outdated
|
|
||
|
|
||
| class MarinePool: | ||
| _marine_instance = None |
There was a problem hiding this comment.
`_marine_instance: ClassVar[Optional[Marine]] = None
marine/marine_pool.py
Outdated
| ) | ||
|
|
||
| @staticmethod | ||
| def _init_marine(lib_path): |
There was a problem hiding this comment.
Switch to classmethod if Pool supports it.
marine/marine_pool.py
Outdated
| ctx = multiprocessing.get_context("spawn") | ||
| # Using spawn so child processes won't get the already initialized marine from the parent process. | ||
| self.pool = ctx.Pool(self.process_count) | ||
| self.pool.map(MarinePool._init_marine, repeat(self._lib_path, self.process_count)) |
There was a problem hiding this comment.
Pool accepts an initializer argument, exactly for that reason
marine/marine_pool.py
Outdated
| MarinePool._marine_instance = Marine(lib_path) | ||
|
|
||
| @staticmethod | ||
| def _filter_and_parse(*args): |
There was a problem hiding this comment.
Switch to classmethod if Pool supports it.
| return MarinePool(marine_so_path) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session", params=[False, True], ids=["marine", "marine_pool"]) |
There was a problem hiding this comment.
I meant in here, not in every test
tomlegkov
left a comment
There was a problem hiding this comment.
Please also add MarinePool to the benchmark
marine/marine_pool.py
Outdated
|
|
||
| def __init__(self, lib_path: str, process_count: int = 4): | ||
| self._lib_path = lib_path | ||
| self.process_count = process_count |
There was a problem hiding this comment.
Why is process_count not private? Do we want to support editing it outside of the constructor?
marine/marine_pool.py
Outdated
| MarinePool._marine_instance = Marine(lib_path) | ||
|
|
||
| @staticmethod | ||
| def _filter_and_parse(*args): |
There was a problem hiding this comment.
What's the advantage of using *args over explicitly stating the parameters?
Also missing return type
marine/marine_pool.py
Outdated
| ) | ||
|
|
||
| @staticmethod | ||
| def _init_marine(lib_path): |
|
To add to what @yehonatanz said, I think what's missing is a complete test for |
5dfc53a to
fb729fd
Compare
2c41cec to
8b5c429
Compare
No description provided.