Slow response times when intercepting pod traffic
alextricity25 opened this issue · comments
Describe the bug
I have a web service that I am intercepting traffic for. The intercept works as expected, but my page load times are 3-5 seconds. When I stop the intercept, the load times are typically less than 1 second.
My web service also connects to the database server in the cluster, which I may suspect is the reason for the slowness. Still, I wouldn't expect this kind of latency between my intercepted pod (running on my workstation) and the database it's connecting to on the cluster.
To Reproduce
Steps to reproduce the behavior:
- When I run
telepresence intercept xrdm-portal --port 80:80 --docker-build ./devops/local-development --docker-build-opt file=./devops/local-development/Dockerfile.portal-web-watch -- --rm --name blah -e WATCH=true -v ./apps/portal:/app/ IMAGE
- I see a new pod spin up, and when I visit the service in my kubernetes cluster, it successfully directs traffic to the service running on my local workstation. However, the app is extremely slow.
Expected behavior
I expect that the response times are marginally slower, but not significantly slower.
Versions (please complete the following information):
- Output of
telepresence version
OSS Client : v2.17.0
OSS Daemon in container: v2.17.0
Traffic Manager : v2.19.0
- Operating system of workstation running
telepresence
commands:
macOS 14.3.1
- Kubernetes environment and Version [e.g. Minikube, bare metal, Google Kubernetes Engine]:
GKE - 1.27.8-gke.1067004
I've managed to pin this down to the connection my web app is making to the postgresql service running in the cluster.
I have created a script to test the latency of SQL requests from the web service to the database, and here are the results.
When I run the script on the web service running in the cluster, I get almost zero latency (as expected since postgresql is also running in the cluster):
However, when I intercept that service and run the same script from the intercepted service running on my laptop, the execution time for this script significantly increases:
Here, I am connecting to the postgresql database running on the k8s cluster from the intercepted service running on my laptop inside a Docker container.
Is it normal for Telepresence to have this much latency when an intercepted service is trying to reach another service running in the cluster? The way I see it, this is what is happening:
1 - The client connects to the web service running in the k8s cluster.
2 - The web service receives the connection, and is intercepted by the telepresence traffic agent sidecar.
3 - The agent sends that request to the traffic manager.
4 through 5 - The traffic manager sends that request to the daemon running on my laptop
6 - The web service on my laptop recieves the request
7 - The web services needs to connect to the database, it makes a connection to the database service running in the k8s cluster
8 - The traffic manager receives that connection, and sends it off to the postgresql pod running in the cluster.
9 - postgresql receives that connection.
![image](https://private-user-images.githubusercontent.com/4964964/318512240-9319b68a-1f48-4fc0-91b0-3052f36e2df2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkzNDMyNDAsIm5iZiI6MTcxOTM0Mjk0MCwicGF0aCI6Ii80OTY0OTY0LzMxODUxMjI0MC05MzE5YjY4YS0xZjQ4LTRmYzAtOTFiMC0zMDUyZjM2ZTJkZjIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjVUMTkxNTQwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2E5MjNlN2M2MzJkMWQwNWFmMjAyYWI5ZjJlMmJlOTMyNDJhZmJlNjY5YzkzMWQxMzdlYmIyMGQ1ZTY3N2ExNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.3Cmc1ClJuKmYItPgkvavGdJW8fbRzEPQv2iu65bhevk)
Is this a correct understanding of what is happening?
A small update here,
I created a k8s port forward to my database service, then created a docker socat container to forward traffic to my docker host machine on port 5473. I also changed the DB_HOST
environment variable on my web service to my docker host. This way, connections going to the database from my local service would be utilizing the k8s port forward instead of Telepresence.
I saw only a marginal decrease in latency. It seems like there may be something else going on here specific to my cluster.
At this point, I am not convinced that this is a Telepresence issue. This seems more like an issue with the connection to my database running in k8s. Closing this for now.
Your understanding of what's going on is mostly correct, but it reflects the old (pre-2.17.0) behavior. Today Telepresence will set up a direct tunnel between the client and the traffic-agent. The traffic-manager is not involved and will not route traffic once an intercept is established. There's one exception to that rule and that is if the client isn't permitted to do a port-forward to the traffic-agent. In such situations, Telepresence will fall back to the old behavior.