Skip to content
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

Support server refresh concurrency #2537

Merged
merged 11 commits into from
Dec 18, 2023
Merged

Conversation

keatonLiu
Copy link
Contributor

We can simultaneously refresh all servers instead of refresh them one by one, which can greatly improve startup speed without visible loss of accuracy

@jedisct1
Copy link
Member

Sure, but by doing so, the latency measurements become unreliable. Not so much of an issue with a super snappy WiFi network, but this is an issue when the link is not that great.

@jedisct1
Copy link
Member

For DoH/ODoH/DoOH servers without an IP address, most of these would also use the fallback servers, which is something we want to minimize. With sequential refreshes, as soon as a server is ready, fallback servers can be ignored.

@jedisct1
Copy link
Member

I'm also a bit concerned about CPU/memory usage, as a lot of people are running dnscrypt-proxy on routers with limited resources. It may cause the server to not be able to start at all, or to freeze due to CPU spikes.

Maybe that should be configurable.

@keatonLiu
Copy link
Contributor Author

I agree that it can be configurable, because for most home PC, the bandwidth and cpu cost can be ignored, while achieving significant performance improvement. If use sequential refresh, it may take several minutes to find an optimal path, compared to only a few seconds for simultaneous refresh

@lifenjoiner
Copy link
Member

The model is: burst at a time, finish in several seconds.

I would suggest setting the Maximum Concurrency.

Besides the advantage and previous disadvantages, think about:

  1. 300+ at a time could be suspicious, in security.
  2. If there is a network accident for 10s, there could be no available servers.

@lifenjoiner
Copy link
Member

@keatonLiu
It's a pity that a good idea lost contact.
I've pushed my suggestions to your update branch.

@keatonLiu
Copy link
Contributor Author

@keatonLiu It's a pity that a good idea lost contact. I've pushed my suggestions to your update branch.

Thank you for your ideas, I'm recently busy looking for an internship, I'll check it out and update soon.

@keatonLiu
Copy link
Contributor Author

keatonLiu commented Dec 11, 2023

I think if the liveServers variable is not atomic there will be a race: 6d179bb

@lifenjoiner
Copy link
Member

Return innerLen and remove liveServers is simpler.

@keatonLiu
Copy link
Contributor Author

Return innerLen and remove liveServers is simpler.

Sure!

@keatonLiu keatonLiu changed the title Simultaneously refresh all servers Support server refresh concurrency Dec 12, 2023
Cover `offline_mode`.
dnscrypt-proxy/serversInfo.go Outdated Show resolved Hide resolved
dnscrypt-proxy/serversInfo.go Outdated Show resolved Hide resolved
@lifenjoiner
Copy link
Member

LGTM.

@lifenjoiner
Copy link
Member

My previous negligence is fixed.

@keatonLiu
Copy link
Contributor Author

how about combine all the ifs together, which looks better

@lifenjoiner
Copy link
Member

how about combine all the ifs together, which looks better

Good catch. But I'm not sure about the first 2.

@lifenjoiner
Copy link
Member

One more thing, the change from Lock() to RLock() will allow serving client requests, on one hand increases the availability, on the other hand could break the sorted latency list.

@keatonLiu
Copy link
Contributor Author

Do you mean that the list will be changed during output? I think RLock only allows concurrent reading, so I don't think the list will be changed during serving client requests. What's more, the sorted list is only about the initialRtt, which is only changed by calling the refresh function.

@lifenjoiner
Copy link
Member

Amend:
... could break the sorted latency log list, if the query log is also written to the same file (stdout for example).

Not saying the serversInfo.inner.

@keatonLiu
Copy link
Contributor Author

Amend: ... could break the sorted latency log list, if the query log is also written to the same file (stdout for example).

Not saying the serversInfo.inner.

Oh, that's very detail, I haven't thought that. Do I need to change back?

@lifenjoiner
Copy link
Member

I'm not saying it's a bad thing. Let's see what @jedisct1 will say.

@lifenjoiner
Copy link
Member

@keatonLiu
I reverted a commit to make this a atomic PR: One PR for one thing.
Those behavior changes are less related to this topic. They may worth a new PR.

@lifenjoiner lifenjoiner merged commit 49e3570 into DNSCrypt:master Dec 18, 2023
1 of 3 checks passed
@lifenjoiner
Copy link
Member

Thank you! You can submit other improvements within new PRs.

@DNSCrypt DNSCrypt locked and limited conversation to collaborators Jan 18, 2024
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.

3 participants