|
| 1 | + |
| 2 | +# Agent for HTC |
| 3 | + |
| 4 | +## Overview |
| 5 | + |
| 6 | +The Agent for HTC is a tool for deploying [Unary GRPC](https://grpc.io/docs/what-is-grpc/core-concepts/#unary-rpc) services. This an RPC service |
| 7 | +that takes in a [protobuf message](https://protobuf.dev/overview/) and returns a |
| 8 | +protobuf message. |
| 9 | + |
| 10 | +This can use the [loadtest](../loadtest) or [american-option](../american-option) as |
| 11 | +workloads and will be used in this example. Your own workload can be used as well. |
| 12 | + |
| 13 | +## Agent Modes |
| 14 | + |
| 15 | +The Agent is intended to be deployed as a sidecar to the gRPC service. It can |
| 16 | +be deployed in [Cloud Run](https://cloud.google.com/run) or [Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine). Cloud Run |
| 17 | +provides scale-to-zero, rapid scaling, and a fully managed service. Google |
| 18 | +Kubernetes Engine provides immense flexibility, scalability, and enterprise control. |
| 19 | + |
| 20 | +The following examples are focused in Cloud Run but some can run on Google Kubernetes |
| 21 | +Engine (or locally). |
| 22 | + |
| 23 | +### BigQuery |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +The agent will be deployed alongside the workload in the same container on Cloud Run. It will |
| 28 | +receive HTTP requests from [BigQuery Remote Functions](https://cloud.google.com/bigquery/docs/remote-functions), converting |
| 29 | +JSON requests into protobuf, dispatching it to the gRPC service, and returning the |
| 30 | +results back to BigQuery as JSON. |
| 31 | + |
| 32 | +This enables flexible data anslysis from BigQuery (or notebook leveraging BigQuery), |
| 33 | +accessing arbitrary gRPC-based services. |
| 34 | + |
| 35 | +### Pub/Sub Push |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +The agent will be deployed alongside the workload in the same container on Cloud Run. It will |
| 40 | +receive HTTP requests from a [Pub/Sub Push Subscription](https://cloud.google.com/pubsub/docs/push). It will |
| 41 | +receive JSON requests, convert into protobuf, dispatching it to the gRPC service, |
| 42 | +and publish the protobuf result as JSON into a topic. |
| 43 | + |
| 44 | +### Pub/Sub |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +The agent will be deployed alongside the workload in the same container on Cloud Run, |
| 49 | +the same container on GKE, or on the same machine. It will |
| 50 | +receive HTTP requests from a [Pub/Sub Subscription](https://cloud.google.com/pubsub/docs/overview). It will |
| 51 | +receive JSON requests from the subscription, convert into protobuf, dispatch it to the gRPC service, |
| 52 | +and publish the protobuf result as JSON into a topic. |
| 53 | + |
| 54 | +### File IO |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +The agent will read from a JSONL file, dispatch each line into gRPC, and write the |
| 59 | +results into a JSONL output file. |
| 60 | + |
| 61 | +This is more intended for testing purposes. |
| 62 | + |
| 63 | +## Test Modes |
| 64 | + |
| 65 | +The Agent also includes two modes for testing: gRPC (direct) and Pub/Sub. |
| 66 | + |
| 67 | +For testing it can be used for latency testing (on-going tests, measuring throughput |
| 68 | +and latency) or for batch (send all data, wait for all results). |
| 69 | + |
| 70 | +TO BE ADDED. |
| 71 | + |
| 72 | +## Testing Locally |
| 73 | + |
| 74 | +NOTE: It is assumed that loadtest tasks have been generated as `../loadtest/tasks.jsonl`, |
| 75 | +and loadtest is running on port 2002. See [loadtest README.md](../loadtest/README.md) |
| 76 | +for instructions on getting it running. |
| 77 | + |
| 78 | +### Build the container |
| 79 | + |
| 80 | +```sh |
| 81 | +docker build -t agent . |
| 82 | +``` |
| 83 | + |
| 84 | +### Running File IO |
| 85 | + |
| 86 | +The following command: |
| 87 | + * Runs the container on the host network (so can connect to the gRPC service) |
| 88 | + * Mounts the local loadtest folder (so it can read the task.jsonl) |
| 89 | + * Runs the "agent file" subcommand with the input and output files. |
| 90 | + * Configures the gRPC endpoint, service, and method for targeting the gRPC service. |
| 91 | + |
| 92 | +```sh |
| 93 | +docker run \ |
| 94 | + --network host \ |
| 95 | + -v $PWD/../loadtest:/data \ |
| 96 | + agent \ |
| 97 | + agent file /data/tasks.jsonl /data/tasks_output.jsonl \ |
| 98 | + --endpoint http://localhost:2002/main.LoadTestService/RunLibrary |
| 99 | +``` |
| 100 | + |
| 101 | +### Running BigQuery |
| 102 | + |
| 103 | +Start the agent in BigQuery RDF mode like with File IO. This will open a port |
| 104 | +on 8080 (on the host) for HTTP requests. |
| 105 | + |
| 106 | +```sh |
| 107 | +docker run \ |
| 108 | + --network host \ |
| 109 | + agent \ |
| 110 | + --logJSON \ |
| 111 | + agent \ |
| 112 | + rdf \ |
| 113 | + --endpoint http://localhost:2002/main.LoadTestService/RunLibrary |
| 114 | +``` |
| 115 | + |
| 116 | +Create an input.json file with the following tasks: |
| 117 | + |
| 118 | +```sh |
| 119 | +cat > input.json <<EOF |
| 120 | +{ |
| 121 | + "requestId": "id1", |
| 122 | + "caller": "caller1", |
| 123 | + "sessionUser": "sessionUser1", |
| 124 | + "userDefinedContext": {}, |
| 125 | + "calls": [ |
| 126 | + [{"task":{"id":"1","minMicros":"500000"}}], |
| 127 | + [{"task":{"id":"2","minMicros":"500000"}}], |
| 128 | + [{"task":{"id":"3","minMicros":"500000"}}], |
| 129 | + [{"task":{"id":"4","minMicros":"500000"}}] |
| 130 | + ] |
| 131 | +} |
| 132 | +EOF |
| 133 | +``` |
| 134 | + |
| 135 | +Use curl to test it out: |
| 136 | + |
| 137 | +```sh |
| 138 | +curl -H "Content-Type: application/json" --data @input.json http://localhost:8080/ |
| 139 | +``` |
| 140 | + |
| 141 | +### Running Pub/Sub |
| 142 | + |
| 143 | +Create the topics and subscriptions: |
| 144 | + |
| 145 | +```sh |
| 146 | +gcloud pubsub topics create test-reqs |
| 147 | +gcloud pubsub subscriptions create --topic test-reqs test-reqs-sub |
| 148 | +gcloud pubsub topics create test-resps |
| 149 | +gcloud pubsub subscriptions create --topic test-resps test-resps-sub |
| 150 | +``` |
| 151 | + |
| 152 | +```sh |
| 153 | +docker run \ |
| 154 | + --network host \ |
| 155 | + agent \ |
| 156 | + agent pubsub \ |
| 157 | + --sub-name projects/your-project-id/subscriptions/test-reqs-sub \ |
| 158 | + --topic-name projects/your-project-id/topics/test-resps \ |
| 159 | + --endpoint http://localhost:2002/main.LoadTestService/RunLibrary |
| 160 | +``` |
| 161 | +Delete the topics and subscriptions: |
| 162 | + |
| 163 | +```sh |
| 164 | +gcloud pubsub subscriptions delete test-reqs-sub |
| 165 | +gcloud pubsub topics delete test-reqs |
| 166 | +gcloud pubsub subscriptions delete test-resps-sub |
| 167 | +gcloud pubsub topics delete test-resps |
| 168 | +``` |
| 169 | + |
| 170 | +Steps: |
| 171 | + * Create two topics and a subscription. |
| 172 | + * Run locally pulling from the subscription and publishing to the topic. |
| 173 | + |
| 174 | + |
| 175 | +### Running Pub/Sub Push |
| 176 | + |
| 177 | +TO BE COMPLETED. |
| 178 | + |
| 179 | +This requires more curl stuff. |
0 commit comments