-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Enable Actor Pool UDFs by default (#3488)
Todo: - [x] fix tests - [ ] add docs (future PR) - [ ] add threaded concurrency (future PR)
- Loading branch information
1 parent
8de0101
commit 56f5089
Showing
36 changed files
with
810 additions
and
1,561 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import multiprocessing as mp | ||
from typing import TYPE_CHECKING | ||
|
||
from daft.expressions import Expression, ExpressionsProjection | ||
from daft.table import MicroPartition | ||
|
||
if TYPE_CHECKING: | ||
from multiprocessing.connection import Connection | ||
|
||
from daft.daft import PyExpr, PyMicroPartition | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def actor_event_loop(uninitialized_projection: ExpressionsProjection, conn: Connection) -> None: | ||
""" | ||
Event loop that runs in a actor process and receives MicroPartitions to evaluate with an initialized UDF projection. | ||
Terminates once it receives None. | ||
""" | ||
initialized_projection = ExpressionsProjection([e._initialize_udfs() for e in uninitialized_projection]) | ||
|
||
while True: | ||
input: MicroPartition | None = conn.recv() | ||
if input is None: | ||
break | ||
|
||
output = input.eval_expression_list(initialized_projection) | ||
conn.send(output) | ||
|
||
|
||
class ActorHandle: | ||
"""Handle class for initializing, interacting with, and tearing down a single local actor process.""" | ||
|
||
def __init__(self, projection: list[PyExpr]) -> None: | ||
self.handle_conn, actor_conn = mp.Pipe() | ||
|
||
expr_projection = ExpressionsProjection([Expression._from_pyexpr(expr) for expr in projection]) | ||
self.actor_process = mp.Process(target=actor_event_loop, args=(expr_projection, actor_conn)) | ||
self.actor_process.start() | ||
|
||
def eval_input(self, input: PyMicroPartition) -> PyMicroPartition: | ||
self.handle_conn.send(MicroPartition._from_pymicropartition(input)) | ||
output: MicroPartition = self.handle_conn.recv() | ||
return output._micropartition | ||
|
||
def teardown(self) -> None: | ||
self.handle_conn.send(None) | ||
self.handle_conn.close() | ||
self.actor_process.join() |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.