pygrpc-native 0.7.0__tar.gz → 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. pygrpc_native-0.7.2/.github/scripts/perf_comment.py +111 -0
  2. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/workflows/ci.yml +22 -0
  3. pygrpc_native-0.7.2/.github/workflows/perf-comment.yml +42 -0
  4. pygrpc_native-0.7.2/.github/workflows/perf.yml +86 -0
  5. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.pre-commit-config.yaml +3 -3
  6. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/CHANGELOG.md +28 -0
  7. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/Cargo.lock +1 -1
  8. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/Cargo.toml +1 -1
  9. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/PKG-INFO +6 -2
  10. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/README.md +4 -1
  11. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/benchmarks/README.md +28 -4
  12. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/benchmarks/echo.py +84 -15
  13. pygrpc_native-0.7.2/benchmarks/regress.py +348 -0
  14. pygrpc_native-0.7.2/examples/README.md +30 -0
  15. pygrpc_native-0.7.2/examples/__init__.py +1 -0
  16. pygrpc_native-0.7.2/examples/aio_server.py +41 -0
  17. pygrpc_native-0.7.2/examples/client.py +19 -0
  18. pygrpc_native-0.7.2/examples/sync_server.py +40 -0
  19. pygrpc_native-0.7.2/interop/_protos.py +18 -0
  20. pygrpc_native-0.7.2/interop/expected_diffs.toml +2 -0
  21. pygrpc_native-0.7.2/interop/protos/src/proto/grpc/testing/empty.proto +28 -0
  22. pygrpc_native-0.7.2/interop/protos/src/proto/grpc/testing/messages.proto +354 -0
  23. pygrpc_native-0.7.2/interop/protos/src/proto/grpc/testing/test.proto +116 -0
  24. pygrpc_native-0.7.2/interop/python_client.py +435 -0
  25. pygrpc_native-0.7.2/interop/run.py +205 -0
  26. pygrpc_native-0.7.2/interop/server.py +66 -0
  27. pygrpc_native-0.7.2/interop/service.py +155 -0
  28. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/pyproject.toml +4 -0
  29. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/python/pygrpc_native/_native.pyi +2 -0
  30. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/python/pygrpc_native/_server.py +7 -1
  31. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/python/pygrpc_native/aio.py +176 -45
  32. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/src/lib.rs +37 -1
  33. pygrpc_native-0.7.2/src/server/auth.rs +72 -0
  34. pygrpc_native-0.7.2/src/server/calls.rs +469 -0
  35. pygrpc_native-0.7.2/src/server/codec.rs +64 -0
  36. pygrpc_native-0.7.2/src/server/connection.rs +326 -0
  37. pygrpc_native-0.7.2/src/server/fallback.rs +76 -0
  38. pygrpc_native-0.7.2/src/server/listener.rs +84 -0
  39. pygrpc_native-0.7.2/src/server/order.rs +85 -0
  40. pygrpc_native-0.7.2/src/server/stream.rs +451 -0
  41. pygrpc_native-0.7.2/src/server.rs +429 -0
  42. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_aio.py +187 -4
  43. pygrpc_native-0.7.2/tests/test_examples.py +42 -0
  44. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_server.py +19 -4
  45. pygrpc_native-0.7.0/src/server.rs +0 -1887
  46. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/CODEOWNERS +0 -0
  47. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  48. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  49. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  50. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  51. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/dependabot.yml +0 -0
  52. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/workflows/dco.yml +0 -0
  53. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/workflows/release.yml +0 -0
  54. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.github/workflows/stale.yml +0 -0
  55. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/.gitignore +0 -0
  56. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/CODE_OF_CONDUCT.md +0 -0
  57. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/CONTRIBUTING.md +0 -0
  58. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/DCO +0 -0
  59. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/LICENSE +0 -0
  60. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/SECURITY.md +0 -0
  61. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/docs/low-level-api.md +0 -0
  62. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/python/pygrpc_native/__init__.py +0 -0
  63. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/python/pygrpc_native/py.typed +0 -0
  64. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/src/metrics.rs +0 -0
  65. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_add_methods.py +0 -0
  66. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_api.py +0 -0
  67. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_bearer_auth.py +0 -0
  68. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_call_details.py +0 -0
  69. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_calls.py +0 -0
  70. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_concurrency_limit.py +0 -0
  71. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_connection.py +0 -0
  72. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_delay_stream_headers.py +0 -0
  73. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_downstream.py +0 -0
  74. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_fallback.py +0 -0
  75. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_front.py +0 -0
  76. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_generic_methods.py +0 -0
  77. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_interceptors.py +0 -0
  78. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_metrics.py +0 -0
  79. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_response_metadata.py +0 -0
  80. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/tests/test_stream_try_send.py +0 -0
  81. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/CHANGELOG.md +0 -0
  82. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/Cargo.toml +0 -0
  83. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/LICENSE-APACHE +0 -0
  84. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/LICENSE-MIT +0 -0
  85. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/README.md +0 -0
  86. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/byte_str.rs +0 -0
  87. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/convert.rs +0 -0
  88. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/error.rs +0 -0
  89. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/extensions.rs +0 -0
  90. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/header/map.rs +0 -0
  91. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/header/mod.rs +0 -0
  92. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/header/name.rs +0 -0
  93. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/header/value.rs +0 -0
  94. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/lib.rs +0 -0
  95. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/method.rs +0 -0
  96. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/request.rs +0 -0
  97. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/response.rs +0 -0
  98. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/status.rs +0 -0
  99. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/uri/authority.rs +0 -0
  100. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/uri/builder.rs +0 -0
  101. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/uri/mod.rs +0 -0
  102. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/uri/path.rs +0 -0
  103. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/uri/port.rs +0 -0
  104. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/uri/scheme.rs +0 -0
  105. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/uri/tests.rs +0 -0
  106. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/src/version.rs +0 -0
  107. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/tests/header_map.rs +0 -0
  108. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/tests/header_map_fuzz.rs +0 -0
  109. {pygrpc_native-0.7.0 → pygrpc_native-0.7.2}/vendor/http/tests/status_code.rs +0 -0
@@ -0,0 +1,111 @@
1
+ """Posts the results of a Perf run on its pull request, or updates the comment
2
+ an earlier run posted. Run by perf-comment.yml, next to the run's results.json
3
+ and pr.json.
4
+
5
+ Both files come from a job that ran the pull request's code, so only numbers
6
+ and known names are read from them, and the comment only goes to a pull
7
+ request whose head is the commit the run tested.
8
+ """
9
+
10
+ import json
11
+ import os
12
+ import re
13
+ import subprocess
14
+ import sys
15
+
16
+ MARKER = "<!-- perf-results -->"
17
+ METRICS = {"cpu_us": "CPU µs/call", "vcs": "context switches/call"}
18
+ VERDICTS = {"no change", "improvement", "suspect", "regression"}
19
+ FLAGGED = {"suspect", "regression"}
20
+ SCENARIO = re.compile(r"[\w .()-]{1,60}")
21
+ SHA = re.compile(r"[0-9a-f]{40}")
22
+ VERSION = re.compile(r"[0-9][0-9a-z.]{0,20}")
23
+
24
+
25
+ def gh(*args: str, body: dict | None = None) -> str:
26
+ cmd = ["gh", "api", *args]
27
+ if body is not None:
28
+ cmd += ["--input", "-"]
29
+ return subprocess.run(
30
+ cmd,
31
+ input=None if body is None else json.dumps(body),
32
+ capture_output=True,
33
+ text=True,
34
+ check=True,
35
+ ).stdout
36
+
37
+
38
+ def render(results: dict, base: str, head: str, run_url: str) -> str:
39
+ env = results.get("environment", {})
40
+ cpus = env.get("cpus")
41
+ grpcio = str(env.get("grpcio", ""))
42
+ rows, flagged, rounds = [], [], 0
43
+ for scenario, metrics in results["results"].items():
44
+ if not SCENARIO.fullmatch(scenario):
45
+ raise ValueError(f"unexpected scenario name: {scenario!r}")
46
+ for key, label in METRICS.items():
47
+ m = metrics[key]
48
+ b, h, change = float(m["base"]), float(m["head"]), float(m["change"])
49
+ worse, verdict = int(m["worse"]), m["verdict"]
50
+ if verdict not in VERDICTS:
51
+ raise ValueError(f"unexpected verdict: {verdict!r}")
52
+ rounds = len(m["head_runs"])
53
+ if verdict in FLAGGED:
54
+ flagged.append(f"{scenario}, {label} {change:+.1%} ({verdict})")
55
+ verdict = f"**{verdict}**"
56
+ rows.append(
57
+ f"| {scenario} | {label} | {b:.2f} | {h:.2f} | {change:+.1%} "
58
+ f"| {worse}/{rounds} | {verdict} |"
59
+ )
60
+ where = f"{cpus} CPUs" if isinstance(cpus, int) else "one runner"
61
+ if VERSION.fullmatch(grpcio):
62
+ where += f", grpcio {grpcio}"
63
+ lines = [
64
+ MARKER,
65
+ "### Perf: server cost per call",
66
+ "",
67
+ f"Head `{head[:7]}` against base `{base[:7]}`, {rounds} rounds in random "
68
+ f"order on one runner ({where}). [Run]({run_url})",
69
+ "",
70
+ ]
71
+ if flagged:
72
+ lines += ["Worth a look:", *(f"- {f}" for f in flagged), ""]
73
+ lines += [
74
+ "| Scenario | Metric | Base | Head | Change | Head worse | Verdict |",
75
+ "|:--|:--|--:|--:|--:|--:|:--|",
76
+ *rows,
77
+ ]
78
+ return "\n".join(lines) + "\n"
79
+
80
+
81
+ def main() -> None:
82
+ repo, head, run_url = (
83
+ os.environ["REPO"],
84
+ os.environ["HEAD_SHA"],
85
+ os.environ["RUN_URL"],
86
+ )
87
+ with open("pr.json") as f:
88
+ meta = json.load(f)
89
+ pr, base = meta.get("pr"), str(meta.get("base", ""))
90
+ if not isinstance(pr, int) or not SHA.fullmatch(head) or not SHA.fullmatch(base):
91
+ sys.exit("pr.json doesn't hold a pull request number and a base commit")
92
+ if json.loads(gh(f"repos/{repo}/pulls/{pr}"))["head"]["sha"] != head:
93
+ print(f"#{pr} isn't at {head[:7]} any more, so the results are stale")
94
+ return
95
+ with open("results.json") as f:
96
+ body = render(json.load(f), base, head, run_url)
97
+ ids = gh(
98
+ "--paginate",
99
+ f"repos/{repo}/issues/{pr}/comments",
100
+ "--jq",
101
+ '.[] | select(.user.login == "github-actions[bot]" '
102
+ f'and (.body | startswith("{MARKER}"))) | .id',
103
+ ).split()
104
+ if ids:
105
+ gh("-X", "PATCH", f"repos/{repo}/issues/comments/{ids[0]}", body={"body": body})
106
+ else:
107
+ gh("-X", "POST", f"repos/{repo}/issues/{pr}/comments", body={"body": body})
108
+
109
+
110
+ if __name__ == "__main__":
111
+ main()
@@ -65,3 +65,25 @@ jobs:
65
65
  maturin build --release --locked --out dist
66
66
  python -m pip install dist/*.whl
67
67
  - run: pytest -q tests
68
+
69
+ interop:
70
+ runs-on: ubuntu-latest
71
+ steps:
72
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
73
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
74
+ with:
75
+ python-version: "3.12"
76
+ - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
77
+ with:
78
+ go-version: stable
79
+ cache: false
80
+ - uses: dtolnay/rust-toolchain@stable
81
+ - name: Build and install
82
+ run: |
83
+ python -m pip install maturin grpcio grpcio-tools
84
+ maturin build --release --locked --out dist
85
+ python -m pip install dist/*.whl
86
+ GOBIN="$RUNNER_TEMP" go install google.golang.org/grpc/interop/client@v1.77.0
87
+ - run: python interop/run.py --go-client "$RUNNER_TEMP/client" --table interop-results.md
88
+ - if: always()
89
+ run: cat interop-results.md >> "$GITHUB_STEP_SUMMARY"
@@ -0,0 +1,42 @@
1
+ name: Perf comment
2
+
3
+ # Posts the results of a Perf run on its pull request. It's a separate
4
+ # workflow so that it can write to pull requests from forks too. It never runs
5
+ # their code: the script comes from the default branch and only reads numbers
6
+ # from the results.
7
+
8
+ on:
9
+ workflow_run:
10
+ workflows: [Perf]
11
+ types: [completed]
12
+
13
+ permissions:
14
+ actions: read
15
+ contents: read
16
+ pull-requests: write
17
+
18
+ jobs:
19
+ comment:
20
+ if: >-
21
+ github.event.workflow_run.event == 'pull_request' &&
22
+ github.event.workflow_run.conclusion == 'success'
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
26
+ with:
27
+ sparse-checkout: .github/scripts
28
+ persist-credentials: false
29
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
30
+ with:
31
+ name: perf-results
32
+ path: results
33
+ run-id: ${{ github.event.workflow_run.id }}
34
+ github-token: ${{ github.token }}
35
+ - name: Comment
36
+ working-directory: results
37
+ env:
38
+ GH_TOKEN: ${{ github.token }}
39
+ REPO: ${{ github.repository }}
40
+ HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
41
+ RUN_URL: ${{ github.event.workflow_run.html_url }}
42
+ run: python3 ../.github/scripts/perf_comment.py
@@ -0,0 +1,86 @@
1
+ name: Perf
2
+
3
+ # Compares a change with its base on the same runner. Advisory: the job passes
4
+ # and the results go to the job summary, and perf-comment.yml posts them on
5
+ # the pull request.
6
+
7
+ on:
8
+ pull_request:
9
+ paths:
10
+ - "src/**"
11
+ - "python/**"
12
+ - "Cargo.toml"
13
+ - "Cargo.lock"
14
+ - "benchmarks/regress.py"
15
+ - ".github/workflows/perf.yml"
16
+ workflow_dispatch:
17
+ inputs:
18
+ base:
19
+ description: "Ref to compare against (default: the same commit)"
20
+ required: false
21
+
22
+ permissions:
23
+ contents: read
24
+
25
+ concurrency:
26
+ group: perf-${{ github.ref }}
27
+ cancel-in-progress: true
28
+
29
+ env:
30
+ GRPCIO: "1.85.1"
31
+
32
+ jobs:
33
+ compare:
34
+ runs-on: ubuntu-latest
35
+ timeout-minutes: 40
36
+ steps:
37
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38
+ with:
39
+ path: head
40
+ fetch-depth: 2
41
+ - name: Pick the base
42
+ id: base
43
+ env:
44
+ INPUT_BASE: ${{ inputs.base }}
45
+ run: |
46
+ if [ "$GITHUB_EVENT_NAME" = pull_request ]; then
47
+ # The merge commit's first parent, so only the PR's changes differ.
48
+ echo "ref=$(git -C head rev-parse HEAD^1)" >> "$GITHUB_OUTPUT"
49
+ else
50
+ echo "ref=${INPUT_BASE:-$GITHUB_SHA}" >> "$GITHUB_OUTPUT"
51
+ fi
52
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
53
+ with:
54
+ ref: ${{ steps.base.outputs.ref }}
55
+ path: base
56
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
57
+ with:
58
+ python-version: "3.12"
59
+ - uses: dtolnay/rust-toolchain@stable
60
+ - name: Build both
61
+ run: |
62
+ python -m pip install maturin "grpcio==$GRPCIO"
63
+ for b in base head; do
64
+ (cd "$b" && maturin build --release --locked --out "../dist-$b")
65
+ python -m venv "venv-$b"
66
+ "venv-$b/bin/pip" install "grpcio==$GRPCIO" dist-$b/*.whl
67
+ done
68
+ - name: Compare
69
+ run: |
70
+ python head/benchmarks/regress.py \
71
+ --base venv-base/bin/python --head venv-head/bin/python \
72
+ --json results.json --summary "$GITHUB_STEP_SUMMARY"
73
+ - name: Note the pull request
74
+ if: github.event_name == 'pull_request'
75
+ env:
76
+ PR: ${{ github.event.pull_request.number }}
77
+ BASE: ${{ steps.base.outputs.ref }}
78
+ run: |
79
+ jq -n --argjson pr "$PR" --arg base "$BASE" '{pr: $pr, base: $base}' > pr.json
80
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
81
+ if: always()
82
+ with:
83
+ name: perf-results
84
+ path: |
85
+ results.json
86
+ pr.json
@@ -10,9 +10,9 @@ repos:
10
10
  rev: v2.4.1
11
11
  hooks:
12
12
  - id: codespell
13
- exclude: ^Cargo\.lock$
14
- # "te" is an HTTP/2 header name.
15
- args: [--ignore-words-list, te]
13
+ exclude: ^(Cargo\.lock|interop/protos/.*)$
14
+ # "te" is an HTTP/2 header name; COMPRESSABLE is a name in the interop protos.
15
+ args: [--ignore-words-list, "te,compressable"]
16
16
  - repo: local
17
17
  hooks:
18
18
  - id: rust-fmt
@@ -4,6 +4,34 @@ All notable changes are listed here. The project follows
4
4
  [semantic versioning](https://semver.org); see
5
5
  [Compatibility](README.md#compatibility) for what that covers.
6
6
 
7
+ ## 0.7.2 (2026-11-03)
8
+
9
+ ### Changed
10
+
11
+ - `aio.server()` takes events on its event loop instead of a dispatch thread,
12
+ which cuts its server CPU per call by about 27% in a unary echo. (#107)
13
+ - On `aio.server()`, small stream messages that handlers write after a wait,
14
+ such as tokens from an LLM decode step, go to the Rust side together at the
15
+ end of the loop iteration, so the ones for one connection can share a write.
16
+ With 1024 streams this cuts server CPU per message by about 28%. (#115)
17
+
18
+ ### Fixed
19
+
20
+ - `server()` takes `grpc.server()`'s `xds` argument; `xds=True` raises
21
+ `NotImplementedError`. (#105)
22
+ - `peer()` of an IPv6 client is `ipv6:%5B...%5D:port`, as in grpcio. (#111)
23
+ - On `aio.server()`, a client leaving a stream whose writes were waiting for
24
+ room could make the server drop other events that came with it, so a new
25
+ call could wait until its deadline. (#117)
26
+
27
+ ## 0.7.1 (2026-10-31)
28
+
29
+ ### Fixed
30
+
31
+ - A handler that passed a plain int to `set_code()` or `abort()` left the call
32
+ hanging until the client's deadline. The sync server now sends `UNKNOWN` for
33
+ it and the aio server sends the int's status code, as grpcio's servers do.
34
+
7
35
  ## 0.7.0 (2026-10-30)
8
36
 
9
37
  ### Added
@@ -395,7 +395,7 @@ dependencies = [
395
395
 
396
396
  [[package]]
397
397
  name = "pygrpc_native"
398
- version = "0.7.0"
398
+ version = "0.7.2"
399
399
  dependencies = [
400
400
  "bytes",
401
401
  "crossbeam-channel",
@@ -2,7 +2,7 @@
2
2
 
3
3
  [package]
4
4
  name = "pygrpc_native"
5
- version = "0.7.0"
5
+ version = "0.7.2"
6
6
  edition = "2021"
7
7
  license = "Apache-2.0"
8
8
  description = "A gRPC server in Rust that hands calls to Python handlers in batches"
@@ -1,12 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygrpc-native
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Operating System :: POSIX :: Linux
7
7
  Classifier: Operating System :: MacOS
8
8
  License-File: LICENSE
9
9
  Summary: A drop-in grpcio server whose HTTP/2 and gRPC work runs in Rust, outside the GIL
10
+ Keywords: grpc,grpcio,asyncio,http2,rust,pyo3,performance
10
11
  License-Expression: Apache-2.0
11
12
  Requires-Python: >=3.10
12
13
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
@@ -89,6 +90,9 @@ For `grpc.aio`:
89
90
  await server.wait_for_termination()
90
91
  ```
91
92
 
93
+ For runnable sync and asyncio servers with a grpcio client, see
94
+ [examples/README.md](https://github.com/pygrpc/pygrpc-native/blob/main/examples/README.md).
95
+
92
96
  To build from source:
93
97
 
94
98
  ```bash
@@ -135,7 +139,7 @@ the socket. The native server listens on a single insecure port.
135
139
  | | Options |
136
140
  |:--|:--|
137
141
  | Same as grpcio | `grpc.max_receive_message_length`, `grpc.max_send_message_length`, `grpc.keepalive_time_ms`, `grpc.keepalive_timeout_ms`, `grpc.keepalive_permit_without_calls`, `grpc.max_concurrent_streams`, `grpc.max_metadata_size`, `grpc.absolute_max_metadata_size`, `grpc.so_reuseport`, `maximum_concurrent_rpcs` |
138
- | Raise an error | `grpc.max_connection_age_ms`, `grpc.max_connection_age_grace_ms`, `grpc.max_connection_idle_ms`, `grpc.max_allowed_incoming_connections`, response compression, TLS |
142
+ | Raise an error | `grpc.max_connection_age_ms`, `grpc.max_connection_age_grace_ms`, `grpc.max_connection_idle_ms`, `grpc.max_allowed_incoming_connections`, response compression, TLS, `xds=True` |
139
143
  | Ignored | Everything else. grpcio also ignores the many options that only clients read. This includes the limits on client pings, which are accepted but not enforced, and `grpc.http2.max_frame_size`, which grpc-core's flow control overrides anyway. |
140
144
 
141
145
  As in grpcio, a value that isn't an integer is ignored.
@@ -75,6 +75,9 @@ For `grpc.aio`:
75
75
  await server.wait_for_termination()
76
76
  ```
77
77
 
78
+ For runnable sync and asyncio servers with a grpcio client, see
79
+ [examples/README.md](https://github.com/pygrpc/pygrpc-native/blob/main/examples/README.md).
80
+
78
81
  To build from source:
79
82
 
80
83
  ```bash
@@ -121,7 +124,7 @@ the socket. The native server listens on a single insecure port.
121
124
  | | Options |
122
125
  |:--|:--|
123
126
  | Same as grpcio | `grpc.max_receive_message_length`, `grpc.max_send_message_length`, `grpc.keepalive_time_ms`, `grpc.keepalive_timeout_ms`, `grpc.keepalive_permit_without_calls`, `grpc.max_concurrent_streams`, `grpc.max_metadata_size`, `grpc.absolute_max_metadata_size`, `grpc.so_reuseport`, `maximum_concurrent_rpcs` |
124
- | Raise an error | `grpc.max_connection_age_ms`, `grpc.max_connection_age_grace_ms`, `grpc.max_connection_idle_ms`, `grpc.max_allowed_incoming_connections`, response compression, TLS |
127
+ | Raise an error | `grpc.max_connection_age_ms`, `grpc.max_connection_age_grace_ms`, `grpc.max_connection_idle_ms`, `grpc.max_allowed_incoming_connections`, response compression, TLS, `xds=True` |
125
128
  | Ignored | Everything else. grpcio also ignores the many options that only clients read. This includes the limits on client pings, which are accepted but not enforced, and `grpc.http2.max_frame_size`, which grpc-core's flow control overrides anyway. |
126
129
 
127
130
  As in grpcio, a value that isn't an integer is ignored.
@@ -1,7 +1,7 @@
1
1
  # Benchmarks
2
2
 
3
- `echo.py` starts a server with an empty unary handler and calls it from
4
- grpcio clients for a few seconds.
3
+ `echo.py` starts a server with empty unary and server-streaming handlers
4
+ and calls it from grpcio clients for a few seconds.
5
5
 
6
6
  ```bash
7
7
  pip install grpcio pygrpc-native
@@ -10,8 +10,19 @@ python benchmarks/echo.py native-aio 8 4 # server kind, client processes, thr
10
10
 
11
11
  The kinds are `sync` and `aio` for grpcio's servers, `native-sync` and
12
12
  `native-aio` for `pygrpc_native.server()` and `pygrpc_native.aio.server()`,
13
- and `native` for the low-level API. `DUR` (default 5) and `SIZE` (default 64) change the seconds measured and the
14
- payload bytes. The server and the clients share the machine.
13
+ and `native` for the low-level API. `DUR` (default 5) and `SIZE` (default 64)
14
+ change the seconds measured and the payload bytes.
15
+ `METHOD` (unary or stream) and `STREAM_COUNT` (default 10) configure the
16
+ streaming benchmark. With `ITL_MS`, handlers send each message on the next
17
+ tick of a clock with that period, the way an LLM engine emits one token for
18
+ every running request at each decode step. The server and the clients share
19
+ the machine. On Linux the server's CPU per call or message is printed too.
20
+
21
+ ```bash
22
+ METHOD=stream python benchmarks/echo.py native-aio 8 4
23
+ # 1024 streams, each sending a message every 20 ms, all on the same tick
24
+ METHOD=stream ITL_MS=20 STREAM_COUNT=128 SIZE=24 python benchmarks/echo.py native-aio 8 128
25
+ ```
15
26
 
16
27
  Median of three runs, calls/s with the client CPU per call in brackets.
17
28
 
@@ -39,3 +50,16 @@ The clients are grpcio in every row, so at 1x1 they cost about the same
39
50
  whichever server they call. With pygrpc-native at 4x4 and 8x4 the clients make
40
51
  several times more calls on the same cores, which is why their CPU per call
41
52
  goes up.
53
+
54
+ ## Comparing two builds
55
+
56
+ `regress.py` compares the server cost per call of two builds on the same
57
+ machine. The `Perf` workflow runs it on pull requests, and it can be run by
58
+ hand against another ref, such as the last release.
59
+
60
+ ```bash
61
+ python benchmarks/regress.py --base base-venv/bin/python --head head-venv/bin/python
62
+ ```
63
+
64
+ Each interpreter needs its build of pygrpc-native installed, and the one
65
+ running the script needs grpcio. It runs on Linux only.
@@ -1,13 +1,19 @@
1
1
  """Echo benchmark for grpc sync, grpc aio and pygrpc-native.
2
2
 
3
+ Supports unary and server-streaming methods.
3
4
  Usage: python benchmarks/echo.py <kind> <procs> <threads>
4
5
 
5
6
  kind is sync or aio for grpcio, native-sync or native-aio for
6
7
  pygrpc_native.server() and pygrpc_native.aio.server(), or native for the
7
8
  low-level API.
8
9
 
9
- DUR sets the seconds measured (default 5) and SIZE the payload bytes
10
- (default 64). METRICS=1 turns on the native front's metrics.
10
+ DUR sets the seconds measured (default 5), SIZE the payload bytes
11
+ (default 64), METHOD the rpc type (unary or stream, default unary),
12
+ STREAM_COUNT the messages per stream (default 10), and ITL_MS makes
13
+ streaming handlers send each message on the next tick of a clock with
14
+ that period, like an LLM engine that emits a token for every running
15
+ request at each decode step (default 0, no wait).
16
+ METRICS=1 turns on the native front's metrics.
11
17
  """
12
18
 
13
19
  import multiprocessing as mp
@@ -21,7 +27,17 @@ import grpc
21
27
 
22
28
  PAYLOAD = os.urandom(int(os.environ.get("SIZE", "64")))
23
29
  DUR = float(os.environ.get("DUR", "5"))
24
- METHOD = "/bench.Echo/Unary"
30
+ METHOD_TYPE = os.environ.get("METHOD", "unary").lower()
31
+ if METHOD_TYPE not in ("unary", "stream"):
32
+ print(f"Unknown METHOD: {METHOD_TYPE}", file=sys.stderr)
33
+ sys.exit(1)
34
+ STREAM_COUNT = int(os.environ.get("STREAM_COUNT", "10"))
35
+ if STREAM_COUNT < 1:
36
+ print("STREAM_COUNT must be at least 1", file=sys.stderr)
37
+ sys.exit(1)
38
+ ITL = float(os.environ.get("ITL_MS", "0")) / 1000
39
+ METHOD_NAME = "Stream" if METHOD_TYPE == "stream" else "Unary"
40
+ METHOD = f"/bench.Echo/{METHOD_NAME}"
25
41
 
26
42
 
27
43
  def ident(b: bytes) -> bytes:
@@ -49,6 +65,12 @@ def serve(kind: str, port: int) -> None:
49
65
  async def unary(req: bytes, ctx: object) -> bytes:
50
66
  return req
51
67
 
68
+ async def server_stream(req: bytes, ctx: object):
69
+ for _ in range(STREAM_COUNT):
70
+ if ITL:
71
+ await asyncio.sleep(ITL - time.time() % ITL)
72
+ yield req
73
+
52
74
  if kind == "aio":
53
75
  server = grpc.aio.server()
54
76
  else:
@@ -57,7 +79,12 @@ def serve(kind: str, port: int) -> None:
57
79
  server = pygrpc_native.aio.server()
58
80
  server.add_registered_method_handlers(
59
81
  "bench.Echo",
60
- {"Unary": grpc.unary_unary_rpc_method_handler(unary, ident, ident)},
82
+ {
83
+ "Unary": grpc.unary_unary_rpc_method_handler(unary, ident, ident),
84
+ "Stream": grpc.unary_stream_rpc_method_handler(
85
+ server_stream, ident, ident
86
+ ),
87
+ },
61
88
  )
62
89
  server.add_insecure_port(target)
63
90
  await server.start()
@@ -70,6 +97,12 @@ def serve(kind: str, port: int) -> None:
70
97
  def unary(req: bytes, ctx: object) -> bytes:
71
98
  return req
72
99
 
100
+ def server_stream(req: bytes, ctx: object):
101
+ for _ in range(STREAM_COUNT):
102
+ if ITL:
103
+ time.sleep(ITL - time.time() % ITL)
104
+ yield req
105
+
73
106
  if kind == "sync":
74
107
  server = grpc.server(ThreadPoolExecutor(64))
75
108
  else:
@@ -78,7 +111,10 @@ def serve(kind: str, port: int) -> None:
78
111
  server = pygrpc_native.server(ThreadPoolExecutor(64))
79
112
  server.add_registered_method_handlers(
80
113
  "bench.Echo",
81
- {"Unary": grpc.unary_unary_rpc_method_handler(unary, ident, ident)},
114
+ {
115
+ "Unary": grpc.unary_unary_rpc_method_handler(unary, ident, ident),
116
+ "Stream": grpc.unary_stream_rpc_method_handler(server_stream, ident, ident),
117
+ },
82
118
  )
83
119
  server.add_insecure_port(target)
84
120
  server.start()
@@ -88,19 +124,34 @@ def serve(kind: str, port: int) -> None:
88
124
  def client(port: int, threads: int, out: mp.Queue, ready: mp.Queue) -> None:
89
125
  channel = grpc.insecure_channel(f"127.0.0.1:{port}")
90
126
  grpc.channel_ready_future(channel).result(30)
91
- call = channel.unary_unary(METHOD, ident, ident)
127
+ if METHOD_NAME == "Stream":
128
+ call = channel.unary_stream(METHOD, ident, ident)
129
+ else:
130
+ call = channel.unary_unary(METHOD, ident, ident)
92
131
  counts = [0] * threads
93
132
  stop = threading.Event()
94
133
 
95
- def work(i: int) -> None:
96
- while not stop.is_set():
97
- call(PAYLOAD)
98
- counts[i] += 1
134
+ if METHOD_NAME == "Stream":
135
+
136
+ def work(i: int) -> None:
137
+ while not stop.is_set():
138
+ for _ in call(PAYLOAD):
139
+ counts[i] += 1
140
+ else:
141
+
142
+ def work(i: int) -> None:
143
+ while not stop.is_set():
144
+ call(PAYLOAD)
145
+ counts[i] += 1
99
146
 
100
147
  workers = [
101
148
  threading.Thread(target=work, args=(i,), daemon=True) for i in range(threads)
102
149
  ]
103
- call(PAYLOAD)
150
+ if METHOD_NAME == "Stream":
151
+ for _ in call(PAYLOAD):
152
+ pass
153
+ else:
154
+ call(PAYLOAD)
104
155
  ready.put(1)
105
156
  cpu0, t0 = time.process_time(), time.perf_counter()
106
157
  for w in workers:
@@ -115,8 +166,21 @@ def client(port: int, threads: int, out: mp.Queue, ready: mp.Queue) -> None:
115
166
  os._exit(0)
116
167
 
117
168
 
169
+ def cpu_seconds(pid: int) -> float | None:
170
+ # Linux only; elsewhere the server's CPU isn't reported.
171
+ try:
172
+ with open(f"/proc/{pid}/stat") as f:
173
+ fields = f.read().rsplit(")", 1)[1].split()
174
+ except OSError:
175
+ return None
176
+ return (int(fields[11]) + int(fields[12])) / os.sysconf("SC_CLK_TCK")
177
+
178
+
118
179
  def main() -> None:
119
180
  kind, procs, threads = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
181
+ if kind == "native" and METHOD_NAME == "Stream":
182
+ print("The 'native' kind does not support METHOD=stream.", file=sys.stderr)
183
+ sys.exit(1)
120
184
  with socket.socket() as s:
121
185
  s.bind(("127.0.0.1", 0))
122
186
  port = s.getsockname()[1]
@@ -132,15 +196,20 @@ def main() -> None:
132
196
  c.start()
133
197
  for _ in clients:
134
198
  ready.get(timeout=60)
199
+ cpu0, t0 = cpu_seconds(server.pid), time.perf_counter()
135
200
  results = [out.get(timeout=DUR + 60) for _ in clients]
201
+ cpu1, t1 = cpu_seconds(server.pid), time.perf_counter()
136
202
  server.kill()
137
203
  calls = sum(r[0] for r in results)
138
204
  rate = sum(r[0] / r[1] for r in results)
139
205
  cpu_us = 1e6 * sum(r[2] for r in results) / calls
140
- print(
141
- f"{kind:11s} {procs}x{threads}: {rate:9,.0f} calls/s client CPU {cpu_us:6.1f} us/call",
142
- flush=True,
143
- )
206
+ unit = "msgs/s" if METHOD_NAME == "Stream" else "calls/s"
207
+ cpu_unit = "us/msg" if METHOD_NAME == "Stream" else "us/call"
208
+ line = f"{kind:11s} {procs}x{threads}: {rate:9,.0f} {unit} client CPU {cpu_us:6.1f} {cpu_unit}"
209
+ if cpu0 is not None and cpu1 is not None:
210
+ server_us = 1e6 * (cpu1 - cpu0) / (t1 - t0) / rate
211
+ line += f" server CPU {server_us:6.1f} {cpu_unit}"
212
+ print(line, flush=True)
144
213
 
145
214
 
146
215
  if __name__ == "__main__":