Skip to content

feat: set default workspace proxy based on latency #17812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 30, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented May 13, 2025

Auto select the proxy on first load (stored in local storage, so per browser), then defer to user selection. The auto selected proxy will not update again once set.

Closes #14827 (comment)

We initially reverted this here: #8137

We reverted because we used to auto select on each page load. So the workspace proxy could flip from page load to page load. This new change saves the auto selected proxy, and sticks to it. So it will be more stable of a selection

This is what it looks like on page load. Since latencies need to be loaded first, it does "flicker" on the first page load.

Screencast.From.2025-05-13.18-04-56.webm

Testing

The easiest way to test this is to run chromium without web security and use dev.coder.com as your CODER_HOST.

  1. chromium --disable-web-security <- run chrome
  2. Use dev.coder.com with some proxies: CODER_HOST=https://dev.coder.com pnpm --dir ./site dev --host
  • You will have to steal your session cookie from a real login
  1. Manually mess with the latency reports. Throw this code in right before the const update = {
switch (check.id) {
  case "1a3e5eb8-d785-4f7d-9188-2eeab140cd06": // Iowa
	  latencyMS = 300
	  break;
  case "1f78398f-e5ae-4c38-aa89-30222181d443": // Brazil
	  // latencyMS = 300
	  break;
  case "72649dc9-03c7-46a8-bc95-96775e93ddc1": // Australia
	  // latencyMS = 300
	  break;
  case "b6cefb69-cb6f-46e2-9c9c-39c089fb7e42": // Europe
	  // latencyMS = 300
	  break;
  case "c3f5cacf-cab7-49e9-bc78-c329a378b128": // South Africa
	  // latencyMS = 300
	  break;
}
  1. Load your page. Delete your local storage, load it again.

Auto select the proxy on first load, then defer to user selection.
The auto selected proxy will not update again once set.
@Emyrk Emyrk changed the title feat: default workspace proxy based on latency feat: set default workspace proxy based on latency May 13, 2025
@@ -73,6 +74,8 @@ export const useProxyLatency = (
new Date(new Date().getTime() - proxyIntervalSeconds * 1000).toISOString(),
);

const [loaded, setLoaded] = useState(false);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is how I track when the latencies are done loading, since they all come back async

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

On first load should we just not show it until we auto-select? I think that would look better than the flicker.

@Emyrk
Copy link
Member Author

Emyrk commented May 14, 2025

On first load should we just not show it until we auto-select? I think that would look better than the flicker.

@kylecarbs The flicker takes as long as the slowest proxy. If the slowest proxy is 2s, that feels like a long time to not be able to determine what proxy to use? Idk how the other FE components would react to a undefined or null proxy selected.

Tbh though, I don't think the flicker is that huge of a deal. It will only happen the first time you authenticate and load the page. Then we save the choice to local storage, and it never changes (unless you select something else).

So the flicker happens once per user per device, and then never again. 🤷

@Emyrk Emyrk requested a review from kylecarbs May 14, 2025 01:13
@spikecurtis
Copy link
Contributor

This could give you suboptimal results because AFAIK, the latency measurement is only browser-to-proxy and doesn't include proxy-to-workspace.

Imagine that you have workspaces and proxies in California and Maine. A Colorado user would always select the California proxy, even if the workspace is in Maine.

@ibetitsmike
Copy link
Contributor

Another interesting behavior is "auto selected proxy will not update again once set". I'd asssume if we have forward deployed engineers who travel to work with customers they'd need to select the proxy either way.

Could there be a softer way to solve this? When you open the dashboard you get a "notification" or another UI indicator "We've detected a proxy with lower latency. Do you want to switch?"

@Emyrk
Copy link
Member Author

Emyrk commented May 14, 2025

@spikecurtis

This could give you suboptimal results because AFAIK, the latency measurement is only browser-to-proxy and doesn't include proxy-to-workspace.

Imagine that you have workspaces and proxies in California and Maine. A Colorado user would always select the California proxy, even if the workspace is in Maine.

This is true. Workspace -> Proxy latency would be a better metric, but of course that would be different for different workspaces.

It is only suboptimal if a user is between a workspace and a proxy geographically.

proxies drawio

The user in Virginia here always selects the proxy in the north east. But for them, that proxy is the opposite direction as for example the WorkspaceCentral workspace.

The Cali user however, the Cali proxy is pretty much always optimal.

In practice, since we can only select 1 workspace per user, it feels like selecting the closest proxy to the user is going to be the most correct without knowing more information.

Regardless though, we have proxies today and we display latency of the user -> proxy. It does not make sense to our users that the default proxy selected has nothing to do with the latency presented.


@ibetitsmike

Another interesting behavior is "auto selected proxy will not update again once set". I'd asssume if we have forward deployed engineers who travel to work with customers they'd need to select the proxy either way.

Could there be a softer way to solve this? When you open the dashboard you get a "notification" or another UI indicator "We've detected a proxy with lower latency. Do you want to switch?"

We actually had a naive implementation of this originally: #8137

The issue is the latencies presented are not very consistent, and can easily "wiggle" +/-40ms. If you lived in US central, and you had a proxy on US east and US west. You could get this notification every page load as each coast can be better on any given ping.

This inconsistency is why we disabled auto selecting proxies, because it was changing quite frequently for some users. And this changes the links of your apps, so it's not transparent to the user.

This solution tries to find a balance between auto selecting and manual switching. We only auto select on first login (per browser, as we save to local storage). Then we let the user control it.

The behavior today is we default to the primary Coderd, then let the user control it.

So it's really just a minor QoL for first time Coder users.

@Emyrk
Copy link
Member Author

Emyrk commented May 19, 2025

@ibetitsmike @spikecurtis @kylecarbs are any of your comments blocking?

@spikecurtis
Copy link
Contributor

mine is not blocking

@ibetitsmike
Copy link
Contributor

@Emyrk not blocking too

@Emyrk Emyrk requested a review from jaaydenh May 27, 2025 18:12
@kylecarbs
Copy link
Member

not blocking

@Emyrk Emyrk merged commit 4597142 into main May 30, 2025
33 checks passed
@Emyrk Emyrk deleted the stevenmasley/auto_select_first branch May 30, 2025 14:24
@github-actions github-actions bot locked and limited conversation to collaborators May 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggest the closest workspace proxy to users on first sign-in
5 participants