Skip to content

Python UDF credit passing - #1748

Merged
Yicong-Huang merged 35 commits into
masterfrom
ethan-python-udf-credit-flow
Nov 10, 2023
Merged

Yicong-Huang merged 35 commits into
masterfrom
ethan-python-udf-credit-flow

Conversation

@ethanwong16

@ethanwong16 ethanwong16 commented Nov 29, 2022 •

Copy link
Copy Markdown
Contributor

Introduction

This PR takes steps to resolve #1602 : implementation of flow control APIs for python UDF. Currently, flow control and back pressure are not enabled for Python UDF workers, with credits not being calculated or passed. This PR seeks to take the important first step to enable Python flow control by:

  • determining what is needed to calculate credits in Python UDF
  • preparing Python UDF workers with the necessary architecture for credit passing

Solution

The following changes were made to Python workers to support this:

  • modifying data sending / receiving logic in Python / Scala workers and proxies to include sending credits
  • changing data / control handlers to set up credit passing for both data and control messages

Typical data flows involving credit passing for Python UDF workers involve:

  1. Python worker sends message to another worker
  • Python network_sender prepares a message to be sent
  • Python proxy_client is used to send the message to the Scala proxy
  • Scala PythonProxyServer receives message, forwards it to the other worker, and sends back an ack with credit information
  • Python proxy_client awaits credit ack and passes it back to network_sender
  • Python network_sender forwards credit information to logic for flow control / back pressure handling
  1. Another worker sends message to Python worker
  • Other worker sends message, which makes its way to Scala PythonProxyClient, which sends message to Python worker
  • Python proxy_server receives the message and processes it using the data or control handlers defined in network_receiver
  • Python proxy_server sends message back to Scala proxy containing credit-related information
  • Scala PythonProxyClient receives message with credit information and passes this back to the other worker and its flow control unit

Demo

demo480p.mov

Current Issues

There was an investigation into modifying the Python worker's internal queue to calculate credits via the number of batches a worker had inside the queue, but this was put on hold as the queue needs to be refactored. There was also work to set up a flow control unit within the Python worker's network_sender, which would utilize credit information to enable back pressure. This task needed to be wrapped up quickly, so both of these changes will be included in future PRs.

Future TODOs

  • Refactor Python worker's internal queue as needed for control / data messages and to calculate number of batches inside the queue from a particular sender actor
  • Replace dummy credit values with actual credits based on what is to be calculated in network_receiver or received from other workers in PythonProxyServer
  • Finish credit calculation and passing back to other workers / flow control unit inside PythonProxyClient
  • Set up back pressure handling for Python worker in network_sender and inside flow control manager
  • Edit Python UDF test cases to mock PythonProxyServer credit response so Python proxy_client doesn't hang on read

@Yicong-Huang

Copy link
Copy Markdown
Contributor

Thanks for the PR! Will review it soon.

@Xiao-zhen-Liu

Copy link
Copy Markdown
Contributor

Discussion 2022.12.07: Work in progress.

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Left some comments please take care of them.

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had another pass on this PR, it looks correct overall. As it is a step 1, which opens a port for credit passing, we could merge it already. If you have time, we can discuss about the mocking in the test cases, though.

@Xiao-zhen-Liu

Copy link
Copy Markdown
Contributor

Update Apr. 17 2023: @Yicong-Huang will finish this.

@Yicong-Huang Yicong-Huang changed the title Python UDF Credit Passing Python UDF credit passing May 17, 2023
# Conflicts:
#	core/amber/src/main/python/core/proxy/proxy_client.py
#	core/amber/src/main/python/core/proxy/proxy_server.py
#	core/amber/src/main/python/core/runnables/test_network_receiver.py
#	core/amber/src/main/scala/edu/uci/ics/amber/engine/architecture/pythonworker/PythonProxyClient.scala
#	core/amber/src/main/scala/edu/uci/ics/amber/engine/architecture/pythonworker/PythonProxyServer.scala
#	core/amber/src/main/scala/edu/uci/ics/amber/engine/architecture/pythonworker/PythonWorkflowWorker.scala
@Yicong-Huang
Yicong-Huang merged commit ebbc8fa into master Nov 10, 2023
@Yicong-Huang
Yicong-Huang deleted the ethan-python-udf-credit-flow branch November 10, 2023 00:39
Xiao-zhen-Liu pushed a commit that referenced this pull request Jan 16, 2024
Introduction 
---
This PR takes steps to resolve #1602 : implementation of flow control
APIs for python UDF. Currently, flow control and back pressure are not
enabled for Python UDF workers, with credits not being calculated or
passed. This PR seeks to take the important first step to enable Python
flow control by:
- determining what is needed to calculate credits in Python UDF
- preparing Python UDF workers with the necessary architecture for
credit passing

Solution
---
The following changes were made to Python workers to support this:

- modifying data sending / receiving logic in Python / Scala workers and
proxies to include sending credits
- changing data / control handlers to set up credit passing for both
data and control messages

Typical data flows involving credit passing for Python UDF workers
involve:
1) Python worker sends message to another worker
- Python `network_sender` prepares a message to be sent
- Python `proxy_client` is used to send the message to the Scala proxy
- Scala `PythonProxyServer` receives message, forwards it to the other
worker, and sends back an ack with credit information
- Python `proxy_client` awaits credit ack and passes it back to
`network_sender`
- Python `network_sender` forwards credit information to logic for flow
control / back pressure handling

2) Another worker sends message to Python worker
- Other worker sends message, which makes its way to Scala
`PythonProxyClient`, which sends message to Python worker
- Python `proxy_server` receives the message and processes it using the
data or control handlers defined in `network_receiver`
- Python `proxy_server` sends message back to Scala proxy containing
credit-related information
- Scala `PythonProxyClient` receives message with credit information and
passes this back to the other worker and its flow control unit

Demo
---


https://user-images.githubusercontent.com/57075492/204417541-2b3d9694-cdb4-42a5-84a0-416715ef8fcd.mov



Current Issues
---
There was an investigation into modifying the Python worker's internal
queue to calculate credits via the number of batches a worker had inside
the queue, but this was put on hold as the queue needs to be refactored.
There was also work to set up a flow control unit within the Python
worker's network_sender, which would utilize credit information to
enable back pressure. This task needed to be wrapped up quickly, so both
of these changes will be included in future PRs.

Future TODOs
---
- Refactor Python worker's internal queue as needed for control / data
messages and to calculate number of batches inside the queue from a
particular sender actor
- Replace dummy credit values with actual credits based on what is to be
calculated in `network_receiver` or received from other workers in
`PythonProxyServer`
- Finish credit calculation and passing back to other workers / flow
control unit inside `PythonProxyClient`
- Set up back pressure handling for Python worker in `network_sender`
and inside flow control manager
- Edit Python UDF test cases to mock `PythonProxyServer` credit response
so Python `proxy_client` doesn't hang on read

---------

Co-authored-by: Yicong Huang <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
Introduction 
---
This PR takes steps to resolve apache#1602 : implementation of flow control
APIs for python UDF. Currently, flow control and back pressure are not
enabled for Python UDF workers, with credits not being calculated or
passed. This PR seeks to take the important first step to enable Python
flow control by:
- determining what is needed to calculate credits in Python UDF
- preparing Python UDF workers with the necessary architecture for
credit passing

Solution
---
The following changes were made to Python workers to support this:

- modifying data sending / receiving logic in Python / Scala workers and
proxies to include sending credits
- changing data / control handlers to set up credit passing for both
data and control messages

Typical data flows involving credit passing for Python UDF workers
involve:
1) Python worker sends message to another worker
- Python `network_sender` prepares a message to be sent
- Python `proxy_client` is used to send the message to the Scala proxy
- Scala `PythonProxyServer` receives message, forwards it to the other
worker, and sends back an ack with credit information
- Python `proxy_client` awaits credit ack and passes it back to
`network_sender`
- Python `network_sender` forwards credit information to logic for flow
control / back pressure handling

2) Another worker sends message to Python worker
- Other worker sends message, which makes its way to Scala
`PythonProxyClient`, which sends message to Python worker
- Python `proxy_server` receives the message and processes it using the
data or control handlers defined in `network_receiver`
- Python `proxy_server` sends message back to Scala proxy containing
credit-related information
- Scala `PythonProxyClient` receives message with credit information and
passes this back to the other worker and its flow control unit

Demo
---


https://user-images.githubusercontent.com/57075492/204417541-2b3d9694-cdb4-42a5-84a0-416715ef8fcd.mov



Current Issues
---
There was an investigation into modifying the Python worker's internal
queue to calculate credits via the number of batches a worker had inside
the queue, but this was put on hold as the queue needs to be refactored.
There was also work to set up a flow control unit within the Python
worker's network_sender, which would utilize credit information to
enable back pressure. This task needed to be wrapped up quickly, so both
of these changes will be included in future PRs.

Future TODOs
---
- Refactor Python worker's internal queue as needed for control / data
messages and to calculate number of batches inside the queue from a
particular sender actor
- Replace dummy credit values with actual credits based on what is to be
calculated in `network_receiver` or received from other workers in
`PythonProxyServer`
- Finish credit calculation and passing back to other workers / flow
control unit inside `PythonProxyClient`
- Set up back pressure handling for Python worker in `network_sender`
and inside flow control manager
- Edit Python UDF test cases to mock `PythonProxyServer` credit response
so Python `proxy_client` doesn't hang on read

---------

Co-authored-by: Yicong Huang <[email protected]>
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 25, 2026
…9686)

### What changes were proposed in this PR?

Remove code that nothing uses, and constructs that repeat a default or
an alias, from the Python tests, the agent service, three frontend
specs, the AsterixDB source and the RustFS test container, and make an
unreachable error check in the single-node example loader reachable
(**+84/−137 lines**). Only the loader's behavior changes: a workflow
file that `jq` cannot parse is now reported and skipped instead of
aborting the loader.

- **Python tests (14 files):** `test_console_message.py` drops the
unused `internal_queue` and `timed_buffer` fixtures and their imports.
Two tests drop fixture parameters they never read (`executor`,
`a_timestamp`), and `test_proxy_client.py` names an unused loop value
`_`. The others write `dict(...)` calls as literals, return from
fixtures that yield without teardown, drop empty `@pytest.fixture()`
parentheses, merge nested `with` blocks, return a value directly instead
of through a local, take the first element with `next(iter(...))`, and
spell `datetime.timezone.utc`, `socket.timeout` and `bytes()` as
`datetime.UTC`, `TimeoutError` and `b""` (Ruff targets Python 3.11).
- **Agent service:** `src/agent/index.ts` and `src/api/index.ts` only
re-export modules that callers import directly. No file imports either
barrel, and the package entry is `src/index.ts`.
`workflow-system-metadata.ts` drops the unused `OperatorSchema` and
`ValidationError` type imports.
- **Frontend specs:** the dataset and model creator specs drop
`FormsModule` and `HttpClientTestingModule`, which
`createFormlyModalFixture` already provides, and the admin Gmail spec
drops three modules that the standalone component and its stubbed
service do not need.
- **`load-examples.sh`:** tests the `content=$(jq -c .
"$workflow_file")` assignment in the `if` instead of checking `$?` after
it. The script runs under `set -euo pipefail` and `main` calls
`load_workflows` directly, so the old check could never fire: a workflow
file that `jq` could not parse aborted the loader and skipped the files
after it, although the comment above `FAILURES` calls each failure
deliberately non-fatal. Now `print_error` counts the file, the loop
moves on, and `main` still exits non-zero at the end.
`test_load_examples_sh.sh` adds a case with an unparseable workflow
sorted ahead of a good one.
- **AsterixDB source:** `AsterixDBConnUtil` and `AsterixDBSourceOpExec`
assign the version response and the parsed row once as `val`s instead of
overwriting `null` and `None` placeholders.
- **`RustFSContainer`:** drops the Scaladoc lines saying the console is
left disabled. RustFS 1.0.0 enables the console by default, and the
fixture does not override it.

| Event | PR / Commit |
| --- | --- |
| Introduced by | Python tests: apache#1259 (2021-07-23), apache#1498 (2022-04-15),
apache#1452 (2022-05-13), apache#2067 (2023-07-27), apache#1748 (2023-11-09), apache#2815
(2024-09-05), apache#4520 (2026-04-27), apache#4704, apache#4719 and apache#4795 (2026-05-03),
apache#4893 (2026-05-04), apache#6643 (2026-07-20), apache#6988 (2026-07-29), apache#7374
(2026-08-07), apache#7579 (2026-08-13), apache#8067 (2026-08-29), apache#8542
(2026-09-15), apache#9279 (2026-11-04), apache#8704 (2026-11-05), apache#9623
(2026-11-23); agent service: apache#4020 (2025-11-25), apache#4495 and apache#4540
(2026-04-28); frontend specs: apache#6513 (2026-07-18), apache#6576 (2026-07-20),
apache#8068 (2026-08-28); `load-examples.sh`: apache#4247 (2026-03-02); AsterixDB
source: apache#1044 (2021-02-25); `RustFSContainer`: apache#8542 (2026-09-15) |
| Usage removed by | Creator spec modules: apache#9522 (2026-11-22,
`refactor(frontend): share dataset and model resource UI`) moved both
specs to `createFormlyModalFixture`. Everything else: unused,
unreachable or redundant since introduction. |

As of 2026-11-24:
- The AsterixDB placeholders have been overwritten before any read for
over 5 years.
- The console-message fixtures have been unused for over 2 years.
- The `load-examples.sh` check has been unreachable for almost 9 months.
- The agent-service barrels have had no importer for the 7 months the
service has existed.
- The creator spec modules have been redundant for 2 days.

### Any related issues, documentation, discussions?

Closes apache#9685.

### How was this PR tested?

Ran on this branch and on `main` at `424b2a757a` (Windows 11; Python
3.12 with CI's pinned `ruff` 0.14.7; Node 24 with Yarn 4.14.1; Bun
1.3.13; JDK 17; the loader test in an Alpine container with Bash 5.2.21
and jq 1.7.1):

```bash
cd amber
ruff check src/main/python src/test/python
ruff format --check src/main/python src/test/python
pytest $(git diff --name-only --relative origin/main -- src/test/python)
cd ../agent-service
bun test
bun run typecheck
cd ../frontend
npx ng test --watch=false --include='**/user-dataset-creator.component.spec.ts' --include='**/user-model-creator.component.spec.ts' --include='**/admin-gmail.component.spec.ts'
npx tsc --noEmit -p src/tsconfig.spec.json
yarn prettier-eslint --list-different $(git diff --name-only --relative origin/main -- src)
yarn eslint $(git diff --name-only --relative origin/main -- src)
cd ..
sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.source.sql.*" WorkflowCore/Test/compile WorkflowOperator/scalafmtCheckAll WorkflowCore/scalafmtCheckAll "WorkflowOperator/scalafixAll --check" "WorkflowCore/scalafixAll --check"
bash bin/single-node/tests/test_load_examples_sh.sh
```

- **Python:**
  - Ruff passes on all 218 files.
- The 14 changed test files run 288 tests with the same outcome per test
on both sides: 218 pass, 67 are skipped and 3 fail.
- The three failures are timestamp cases in
`test_ui_parameter_contract.py` that expect UTC and come out 8 hours off
in this machine's time zone. They fail the same way on `main`.
- **Agent service:** all 361 tests in 20 files and the typecheck pass on
both sides.
- **Frontend:** the three specs run 37 tests, all passing on both sides.
The spec typecheck, prettier-eslint and ESLint pass.
- **Scala:** the 11 `source.sql` suites, including the three AsterixDB
specs, run 204 tests that all pass on both sides. WorkflowCore's tests
compile, and scalafmt and scalafix pass on both modules.
- **`load-examples.sh`:** `test_load_examples_sh.sh` passes all 11
checks. Against `main`'s loader, the 9 existing checks pass and the 2
new ones fail: `jq` exits 5 at the malformed file, and the loader stops
there without creating the other workflow.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation of flow control APIs for python UDF

3 participants