aglinxinyuan commented on code in PR #5557: URL: https://github.com/apache/texera/pull/5557#discussion_r3371005419
########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/pythonworker/bench/ArrowFlightActorBench.scala: ########## @@ -0,0 +1,584 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.engine.architecture.pythonworker.bench + +import org.apache.pekko.actor.{Actor, ActorRef, ActorSystem, PoisonPill, Props} +import org.apache.pekko.testkit.TestProbe +import org.apache.texera.amber.clustering.SingleNodeListener +import org.apache.texera.amber.core.executor.OpExecWithCode +import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, Tuple} +import org.apache.texera.amber.core.virtualidentity.{ + ActorVirtualIdentity, + ChannelIdentity, + EmbeddedControlMessageIdentity, + WorkflowIdentity +} +import org.apache.texera.amber.core.workflow.{PhysicalLink, PortIdentity} +import org.apache.texera.amber.engine.architecture.common.WorkflowActor.{NetworkAck, NetworkMessage} +import org.apache.texera.amber.engine.architecture.pythonworker.PythonWorkflowWorker +import org.apache.texera.amber.engine.architecture.rpc.controlcommands._ +import org.apache.texera.amber.engine.architecture.rpc.controlreturns.ReturnInvocation +import org.apache.texera.amber.engine.architecture.scheduling.config.WorkerConfig +import org.apache.texera.amber.engine.architecture.sendsemantics.partitionings.OneToOnePartitioning +import org.apache.texera.amber.engine.common.AmberRuntime +import org.apache.texera.amber.engine.common.ambermessage.{DataFrame, WorkflowFIFOMessage} +import org.apache.texera.amber.engine.common.ambermessage.WorkflowMessage.getInMemSize +import org.apache.texera.amber.util.VirtualIdentityUtils + +import java.io.PrintWriter +import java.nio.file.{Files, Paths} +import scala.concurrent.Await +import scala.concurrent.duration._ + +/** + * End-to-end micro-benchmark of the real Arrow Flight data path through a + * live PythonWorkflowWorker actor. + * + * Each measured config spawns a fresh PythonWorkflowWorker (real Pekko actor, + * real Python subprocess via texera_run_python_worker.py, real Arrow Flight + * transport), wires up an identity Python UDF, and times the round-trip of + * `numBatches` DataFrames send→echo through the actor mailbox. + * + * Output: + * - stdout summary per config + * - benchmark-results.csv (one row per config) — overwritten each run + * + * Run with: + * sbt "WorkflowExecutionService/Test/runMain \ + * org.apache.texera.amber.engine.architecture.pythonworker.bench.ArrowFlightActorBench" + * + * Caveat: `Utils.amberHomePath` does a `Files.walk(cwd, 2).findAny` for any + * dir ending in `amber`. If `.claude/amber/` exists locally, the Python + * subprocess may end up trying to launch from that path; move it aside for + * the run, or fix `amberHomePath` upstream. + */ +object ArrowFlightActorBench { Review Comment: Should we keep the benchmark class in the test folder? Unlike the other tests, it doesn't produce a pass/fail result. Since it's intended for performance measurement, it may be better to place it in a separate benchmark folder. ########## .github/workflows/benchmarks.yml: ########## @@ -0,0 +1,327 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Texera benchmarks — bench-agnostic umbrella workflow. +# +# This file is the single CI entry for ALL Texera performance benchmarks +# (currently Arrow Flight E2E; JMH and others land here as well). The +# workflow knows nothing about specific benches — bin/run-benchmarks.sh +# is the opaque entry point that owns which benches run and where their +# outputs land under bench-results/. Adding a new bench is: +# 1. Append the run command to bin/run-benchmarks.sh. +# 2. Add a `Publish <chart-name>` step block below pointing at the +# bench's JSON output file with the right `tool:` setting. +# This workflow file otherwise stays unchanged. +# +# Triggering — mirrors amber-integration's label gate (NOT file paths): +# - PR: runs only when one of the labels mapped to the amber-integration +# stack in required-checks.yml's LABEL_STACKS is present on the PR. +# Labels are applied by the .github/labeler.yml workflow on opened / +# synchronize, so we wait for that workflow to complete before +# deciding (same pattern required-checks.yml uses). +# - push to main: always runs (same trimmed grid as PR for quick post- +# merge signal) and publishes to gh-pages. +# - schedule (weekly): runs the full 36-config sweep and publishes to +# gh-pages — this is the authoritative long-term baseline. +# - workflow_dispatch: manual full-grid run (no publish; bring-your-own +# trigger for ad-hoc exploration). +# +# Two modes via BENCH_MODE env (read by the bench Scala main): +# pr — 3 configs × 20 batches, ~5 min (PR + push-to-main) +# full — 36 configs × 200 batches, ~50-60 min (schedule + dispatch) +# +# Non-blocking: this workflow is NOT included in required-checks.yml's +# `required-checks` aggregator, so its result doesn't gate merges even +# when it fails. Adding it to branch protection later is a deliberate +# .asf.yaml change. +# +# Permissions: +# contents: write — needed by benchmark-action's auto-push to gh-pages. +# PR runs (which GitHub auto-downgrades to read-only on forks) gate +# auto-push off via the event check, so the missing write is never +# exercised. + +name: Benchmarks Review Comment: Should we add the benchmark to CI? It increases CI runtime, but it isn't actually checking anything right now. I think it would be more valuable if it served as a guardrail—for example, failing the CI when performance exceeds a predefined threshold or regresses beyond an acceptable margin. ########## .github/workflows/benchmarks-pr-comment.yml: ########## @@ -0,0 +1,255 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Posts (or upserts) a PR comment with bench results AFTER the Benchmarks +# workflow completes. +# +# Why a separate workflow_run-triggered file: +# - The Benchmarks workflow runs on `pull_request`, which for fork PRs +# gets a read-only GITHUB_TOKEN and zero secret access — GitHub's +# hard-coded security model. We can't comment from there. +# - `workflow_run` runs in the BASE repo's context (apache/texera) +# with normal token + secret access, so it CAN comment on fork PRs. +# - This is the ASF-approved pattern; `pull_request_target` is policy- +# forbidden for any action that handles tokens. +# +# Why workflow_run is safe here vs pull_request_target: +# - We only READ a small, opaque artifact (pr-number.txt + the bench +# JSON / CSV) produced by the upstream run; we don't execute any +# PR-author code in this workflow. +# - The PR number is validated against ^[0-9]+$ before being used in +# any API call, blocking ref injection. + +name: Benchmarks PR Comment Review Comment: How should we interpret this number? We should have a baseline for comparison; otherwise, it's difficult to tell whether the result is good or bad. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
