Skip to content

Conversation

vdavid
Copy link
Contributor

@vdavid vdavid commented Nov 11, 2024

Adds the src gateway benchmark command to the tool.

https://github.com/sourcegraph/sourcegraph/pull/1526 adds some new endpoints that this benchmarking script uses.

The benchmarking tool compares three two routes using the endpoints added in above PR:

  1. Sourcegraph HTTP → Cody Gateway HTTP
  2. Sourcegraph HTTP → Cody Gateway WebSocket
  3. (There should be a third one: Sourcegraph WebSocket → Cody Gateway WebSocket, but I haven't been able to make that endpoint work so it's currently not added to this script.)

Testing the benchmarking tool locally

(Description WIP)

  • brew install ngrok/ngrok/ngrok if you don't have ngrok
  • Run ngrok http http://localhost:9992
  • Copy the *.ngrok-free.app URL from the "Forwarding" section of ngrok's output to your dev-private/enterprise/dev/site-config.json as the "modelConfiguration" / "sourcegraph" / "endpoint" value.
  • Important note: Actually, when using ngrok, the protocol when calling Cody Gateway in the new endpoint handler has to be wss://, not ws://! (Just a one-char change but it's manual for now.) But when running locally, it needs to be ws://. Something to be mindful of when running this and in the future.
  • Run Sourcegraph: run sg dotcom
  • Run: src gateway benchmark

The output should look like this:

CleanShot 2024-11-07 at 15 01 49@2x

Next steps

Missing work to be done:

  • Add a direct call to Cody Gateway. Endpoints are at:
    • {codyGatewayUrl}/v2/http and
    • {codyGatewayUrl}/v2/websocket.
  • Docs?

Test plan

Tested manually:

  1. go run ./cmd/src lists the new gateway command correctly.
  2. go run ./cmd/src gateway lists the benchmark subcommand correctly.
  3. go run ./cmd/src gateway benchmark runs the benchmarks against the endpoint set in the SRC_ENDPOINT env var correctly.
  4. go run ./cmd/src gateway benchmark --requests 2 sets the number of requests correctly.
  5. SRC_ENDPOINT=http://localhost:3080 go run ./cmd/src gateway benchmark --requests 2 sets the endpoint to my localhost and works correctly.

@vdavid vdavid requested a review from emidoots November 11, 2024 13:34
@emidoots
Copy link
Member

Cool, great starting point! can you get this client talking to / benchmarking 4 endpoints?

e.g. with one test src gateway benchmark -endpoint=$CODY_GATEWAY_URL -sourcegraph=$SG_INSTANCE_URL I'd love for it to benchmark:

  1. {CODY_GATEWAY_URL}/v2 (HTTP)
  2. {CODY_GATEWAY_URL}/v2/websocket (websocket)
  3. {SG_INSTANCE_URL}/.api/gateway (HTTP)
  4. {SG_INSTANCE_URL}/.api/gateway/websocket (websocket)

i.e. if the user passes -endpoint then run (1) and (2), if the user passes -sourcegraph then run (3) and (4), if they pass both then run all 4.

Then the default if you pass nothing can be to run against Cody Gateway prod and Sourcegraph.com

For (2) and (4) you'll need to add a websocket client to this PR, you should be able to do that testing against any websocket server until I have a chance to debug the issue you brought up with doing it in the SG instance.

@vdavid vdavid changed the title Add src gateway benchmark command feat/gateway: Add src gateway benchmark command Nov 14, 2024
@vdavid
Copy link
Contributor Author

vdavid commented Nov 14, 2024

Update:
Fixed all asks in individual messages.

In response to the main message:

  • The -sourcegraph=$SG_INSTANCE_URL param is missing
  • The -endpoint=$CODY_GATEWAY_URL param is missing
  • The direct calls to Cody Gateway are missing.

It's like 20 min to add these but I haven't had the time. Later.

Copy link
Member

@emidoots emidoots left a comment

Choose a reason for hiding this comment

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

Cool, this looks good, I'm going to merge as-is and we can continue iterating in main together

@emidoots emidoots marked this pull request as ready for review November 14, 2024 23:13
@emidoots emidoots requested a review from a team as a code owner November 14, 2024 23:13
@emidoots emidoots merged commit 177b25b into main Nov 14, 2024
8 of 9 checks passed
@emidoots emidoots deleted the dv/add-gateway-benchmark-script branch November 14, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants