Closed dieb closed 5 months ago
Hi @dieb, I wonder if https://github.com/apple/swift-async-dns-resolver/pull/16 might help issue (1)?
Increasing polling time (i.e., issue/option (2)) would slow down the resolver I think, at least that's what I observed in tests locally.
Thanks! Gave #16 a try but still same issue. I added some prints to my code and to your code and looks like QueryProcessor deinit
isn't running. Double-checked my deinit is definitely running.
Edit: checked further and CAresDNSResolver and Ares are definitely getting deinit'ed. It may be just QueryProcessor.
On top of #16 : looks like the modification below works to allow QueryProcessor to deinit, but I'll admit I'm not confident enough in Swift to know whether this is good.
private func schedule() {
self.pollingTask = Task { [weak self] in
try await Task.sleep(nanoseconds: self?.pollIntervalNanos ?? 0)
await self?.poll()
}
}
Testing locally seems to allow cleanup on deref, and when I keep a ref polling continues as expected.
I applied your change with minor tweaks. https://github.com/apple/swift-async-dns-resolver/pull/16/commits/2a38874648327439179aa160958ba2a380a39566
Can you please give it a try?
Thanks! It works.
Awesome! Thanks for checking.
Much appreciated!
Thanks @dieb. Patch: https://github.com/apple/swift-async-dns-resolver/releases/tag/0.1.3
Hi there,
I'm testing using the lib to periodically resolve a list of domains and it works great. I'm using something like this:
During testing I noticed CPU utilization resolving domains is light and reasonable, though I noticed some utilization while idling. CPU idles at 1-2% and goes up to 5% while resolving a list of 30 domains concurrently.
Peeking the code it looks like the 10ms polling here could explain the 1-2% idling, correct? I'm assuming the TODO mentioning the NIO EventLoop could help.
I'm looking for a way to improve the idling 1-2% CPU utilization. Since my traffic pattern is spiky and I'm driving it, I'm thinking it may be possible to improve by getting a new resolver only when needed, then disposing it.
Here are some things I tried with no success:
Any thoughts / recommendations?
Thanks!
PS: Thank you for swift-async-dns-resolver!
Environment: