Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5639541

Browse files
authored
chore: disable auto proxy selection based on latency (#8137)
* chore: disable auto pick proxy based on latency* Remove latency pulled from storage
1 parent82415a6 commit5639541

File tree

3 files changed

+48
-53
lines changed

3 files changed

+48
-53
lines changed

‎site/src/contexts/ProxyContext.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,11 @@ describe("ProxyContextSelection", () => {
264264
expUserProxyID:MockHealthyWildWorkspaceProxy.id,
265265
},
266266
],
267-
// Latency behavior
267+
// Latency behavior is disabled, so the primary should be selected.
268268
[
269269
"regions_default_low_latency",
270270
{
271-
expProxyID:MockHealthyWildWorkspaceProxy.id,
271+
expProxyID:MockPrimaryWorkspaceProxy.id,
272272
regions:MockWorkspaceProxies,
273273
storageProxy:undefined,
274274
latencies:{

‎site/src/contexts/ProxyContext.tsx

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ export const ProxyProvider: FC<PropsWithChildren> = ({ children }) => {
136136
proxiesResp?.regions??[],
137137
loadUserSelectedProxy(),
138138
proxyLatencies,
139+
// Do not auto select based on latencies, as inconsistent latencies can cause this
140+
// to behave poorly.
141+
false,
139142
),
140143
)
141144
},[proxiesResp,proxyLatencies])
@@ -208,6 +211,7 @@ export const getPreferredProxy = (
208211
proxies:Region[],
209212
selectedProxy?:Region,
210213
latencies?:Record<string,ProxyLatencyReport>,
214+
autoSelectBasedOnLatency=true,
211215
):PreferredProxy=>{
212216
// If a proxy is selected, make sure it is in the list of proxies. If it is not
213217
// we should default to the primary.
@@ -219,37 +223,52 @@ export const getPreferredProxy = (
219223
if(!selectedProxy||!selectedProxy.healthy){
220224
// By default, use the primary proxy.
221225
selectedProxy=proxies.find((proxy)=>proxy.name==="primary")
226+
222227
// If we have latencies, then attempt to use the best proxy by latency instead.
223-
if(latencies){
224-
constproxyMap=proxies.reduce((acc,proxy)=>{
225-
acc[proxy.id]=proxy
226-
returnacc
227-
},{}asRecord<string,Region>)
228-
229-
constbest=Object.keys(latencies)
230-
.map((proxyId)=>{
231-
return{
232-
id:proxyId,
233-
...latencies[proxyId],
234-
}
235-
})
236-
// If the proxy is not in our list, or it is unhealthy, ignore it.
237-
.filter((latency)=>proxyMap[latency.id]?.healthy)
238-
.sort((a,b)=>a.latencyMS-b.latencyMS)
239-
.at(0)
240-
241-
// Found a new best, use it!
242-
if(best){
243-
constbestProxy=proxies.find((proxy)=>proxy.id===best.id)
244-
// Default to w/e it was before
245-
selectedProxy=bestProxy||selectedProxy
246-
}
228+
constbest=selectByLatency(proxies,latencies)
229+
if(autoSelectBasedOnLatency&&best){
230+
selectedProxy=best
247231
}
248232
}
249233

250234
returncomputeUsableURLS(selectedProxy)
251235
}
252236

237+
constselectByLatency=(
238+
proxies:Region[],
239+
latencies?:Record<string,ProxyLatencyReport>,
240+
):Region|undefined=>{
241+
if(!latencies){
242+
returnundefined
243+
}
244+
245+
constproxyMap=proxies.reduce((acc,proxy)=>{
246+
acc[proxy.id]=proxy
247+
returnacc
248+
},{}asRecord<string,Region>)
249+
250+
constbest=Object.keys(latencies)
251+
.map((proxyId)=>{
252+
return{
253+
id:proxyId,
254+
...latencies[proxyId],
255+
}
256+
})
257+
// If the proxy is not in our list, or it is unhealthy, ignore it.
258+
.filter((latency)=>proxyMap[latency.id]?.healthy)
259+
.sort((a,b)=>a.latencyMS-b.latencyMS)
260+
.at(0)
261+
262+
// Found a new best, use it!
263+
if(best){
264+
constbestProxy=proxies.find((proxy)=>proxy.id===best.id)
265+
// Default to w/e it was before
266+
returnbestProxy
267+
}
268+
269+
returnundefined
270+
}
271+
253272
constcomputeUsableURLS=(proxy?:Region):PreferredProxy=>{
254273
if(!proxy){
255274
// By default use relative links for the primary proxy.

‎site/src/contexts/useProxyLatency.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,8 @@ const proxyLatenciesReducer = (
2424
state:Record<string,ProxyLatencyReport>,
2525
action:ProxyLatencyAction,
2626
):Record<string,ProxyLatencyReport>=>{
27-
// TODO: We should probably not read from local storage on every action.
28-
consthistory=loadStoredLatencies()
29-
constproxyHistory=history[action.proxyID]||[]
30-
constminReport=proxyHistory.reduce((min,report)=>{
31-
if(min.latencyMS===0){
32-
// Not yet set, so use the new report.
33-
returnreport
34-
}
35-
if(min.latencyMS<report.latencyMS){
36-
returnmin
37-
}
38-
returnreport
39-
},{}asProxyLatencyReport)
40-
41-
if(
42-
minReport.latencyMS>0&&
43-
minReport.latencyMS<action.report.latencyMS
44-
){
45-
// The new report is slower then the min report, so use the min report.
46-
return{
47-
...state,
48-
[action.proxyID]:minReport,
49-
}
50-
}
51-
52-
// Use the new report
27+
// Always return the new report. We have some saved latencies, but until we have a better
28+
// way to utilize them, we will ignore them for all practical purposes.
5329
return{
5430
...state,
5531
[action.proxyID]:action.report,
@@ -65,7 +41,7 @@ export const useProxyLatency = (
6541
proxyLatencies:Record<string,ProxyLatencyReport>
6642
}=>{
6743
// maxStoredLatencies is the maximum number of latencies to store per proxy in local storage.
68-
letmaxStoredLatencies=8
44+
letmaxStoredLatencies=1
6945
// The reason we pull this from local storage is so for development purposes, a user can manually
7046
// set a larger number to collect data in their normal usage. This data can later be analyzed to come up
7147
// with some better magic numbers.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp