IrineSistiana / mosdns-cn

A simple DNS forwarder that can make life easier. (Not maintained)
GNU General Public License v3.0
323 stars 46 forks source link

Cache mechanism is not working #43

Open phantomcraft opened 1 year ago

phantomcraft commented 1 year ago

Command line:

mosdns-cn --cache=10000 --lazy-cache-ttl=1000 --min-ttl=3600 --max-ttl=7200 --server=127.0.0.1:1053 --upstream=114.114.114.114:53

When I dig two times in any domain, the response time is the same:

user@localhost:~$ time dig @127.0.0.1 -p 1053 g.co

; <<>> DiG 9.18.7-1-Debian <<>> @127.0.0.1 -p 1053 g.co
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56208
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;g.co.              IN  A

;; ANSWER SECTION:
g.co.           3600    IN  A   142.250.178.142

;; Query time: 300 msec
;; SERVER: 127.0.0.1#1053(127.0.0.1) (UDP)
;; WHEN: Sun Dec 18 23:54:47 EST 2022
;; MSG SIZE  rcvd: 53

real    0m0.320s
user    0m0.004s
sys 0m0.006s
user@localhost:~$ time dig @127.0.0.1 -p 1053 g.co

; <<>> DiG 9.18.7-1-Debian <<>> @127.0.0.1 -p 1053 g.co
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52969
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;g.co.              IN  A

;; ANSWER SECTION:
g.co.           3600    IN  A   142.250.178.142

;; Query time: 300 msec
;; SERVER: 127.0.0.1#1053(127.0.0.1) (UDP)
;; WHEN: Sun Dec 18 23:54:48 EST 2022
;; MSG SIZE  rcvd: 53

real    0m0.319s
user    0m0.010s
sys 0m0.000s

When using another DNS forwarder the second query is got from the app cache:

user@localhost:~$ time dig @127.0.0.1 -p 1053 g.co

; <<>> DiG 9.18.7-1-Debian <<>> @127.0.0.1 -p 1053 g.co
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9464
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;g.co.              IN  A

;; ANSWER SECTION:
g.co.           118 IN  A   142.250.178.142

;; Query time: 0 msec
;; SERVER: 127.0.0.1#1053(127.0.0.1) (UDP)
;; WHEN: Sun Dec 18 23:56:36 EST 2022
;; MSG SIZE  rcvd: 49

real    0m0.021s
user    0m0.004s
sys 0m0.006s

Something missing in my config?