-
Notifications
You must be signed in to change notification settings - Fork 31
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
Patch to skip blacklist entries in hosts file #38
Comments
Bump |
Blocklisting using For the specific use case where blocklist entries should be ignored, an instance of Generally, I'd not recommend putting such an enormous number of records into |
To discuss performance we'd be happy to have some numbers. What is the environment? How poor is the current performance? How is it improved with this patch? A reproducible benchmark would help us spot which part of the code is slow and optimize it. |
I'll get back to you with numbers. About dnsmasq:
|
$ wc -l /etc/hosts
228858 /etc/hosts $ git diff -U0
diff --git a/lib/resolv.rb b/lib/resolv.rb
index e36dbce..0356591 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -190,0 +191 @@ class Resolv
+ time = Time.now.to_f
@@ -205,0 +207 @@ class Resolv
+ printf "Took %.1fs\n", Time.now.to_f - time Took 0.6s - next unless addr
+ next if !addr || addr.start_with?('0') Took 0.3s $ grep -v \0.\0.\0.\0 < /etc/hosts > /etc/hosts # pretend this works :D
$ wc -l /etc/hosts
69 /etc/hosts Took 0.0s |
PS! |
It looks quite faster than "forever" :) Self-contained benchmark: require 'benchmark/ips'
require 'resolv'
require 'tempfile'
hosts = {
small: 20,
medium: 2000,
large: 200000,
}.transform_values do |size|
f = Tempfile.open('hosts')
f.write("127.0.0.1 localhost\n")
size.times do |i|
f.printf("0.0.0.0 %x.test\n", i)
end
f.tap(&:flush)
end
Benchmark.ips do |x|
x.warmup = 1
x.time = 5
hosts.each do |name, f|
x.report(name) do
Resolv.new([Resolv::Hosts.new(f.path)]).getaddress('localhost')
end
end
x.compare!
end
|
Resolv is a generic library that implements hostname resolution (it's not just a part of So I think optimizing Resolv for a large /etc/hosts database is good, but changing its behavior in the suggested way is not desirable. |
Agree, but a consistent half second delay on all scripts using the library is sluggishly unacceptable. (I think also "forever" might have been longer, but under other circumstances which fail my memory.) See questions about dnsmasq. If that (or any other approach) can alleviate the need for swamping /etc/hosts with 200k+ entries, there is no problem here. |
Initialization takes forever with a large hosts blacklist. Proposing the following patch:
The text was updated successfully, but these errors were encountered: