Coder Social home page Coder Social logo

fwdns's Introduction

fwdns

A DNS Forwarder, with some interesting features.

QuickStart

$ npm i fwdns -g
$ fwdns -h

  Usage: fwdns [options]

  Options:

    -h, --help                                       output usage information
    -V, --version                                    output the version number
    -p, --port [6666]                                Port to bind
    -l, --listen [127.0.0.1]                         Address to listen
    -z, --zone [8.8.8.8]                             Default zone, use system by default
    -t, --timeout [5000]                             Timeout forwarding requests
    --renew-timeout [3600]                           Timeout of auto renewal
    -f, --forward-zone [/path/to/forward/zone.json]  Forward zone setting, {"hosts": ["8.8.8.8"], "names": ["google.com"]}
    -s, --local-zone [/path/to/local/zone.json]      Local zone setting, {"abc.com": "127.0.0.1"}

Features

Fast Zone Switching

It's a very rare edge case for using a DNS forwarder when there is over thousands of forward-zone settings. There is a fork of dnsmasq solving the similar problems, both dnsmasq and unbound's CPU reach 100% over 10K of zones.

With a pre-indexed map, we can archive less then 1ms for the query over 10K zones search, the algorithm is the same as this fork although in JavaScript, the implementation is much more easier. (but slower)

Here is some benchmark result compare to regular loop, (code):

EndsWithLoop#hit x 758 ops/sec ±1.93% (81 runs sampled)
RegExpLoop#hit x 90.88 ops/sec ±1.84% (66 runs sampled)
ReverseIndex#hit x 719,606 ops/sec ±1.02% (83 runs sampled)
EndsWithLoop#miss x 365 ops/sec ±1.26% (77 runs sampled)
RegExpLoop#miss x 114 ops/sec ±1.12% (69 runs sampled)
ReverseIndex#miss x 560,464 ops/sec ±0.91% (83 runs sampled)

Cache and Auto Renewal

All records that get from backends, will be cache in the memory and expire regards to the TTL, via node-cache.

Additionally, a auto renewal policy is added for better performance. When the item is added to the cache, the timer start to renew the result in the right time if possible, right time means 0.8 of TTL, and when the query is not being seen for an hour, give up the next renewal.

Race Query

Sometimes the backend zones can be busy or the network maybe unstable for a while, we can waste some network and CPU resources to duplicate the request to different servers, and take the first response, this can be easily archive by async's race function.

Performance

Might be slightly slower then others at the first time or both hit cache due to JavaScript's performance.

But I think with the auto renewal and race query, this maybe faster then others in the most daily usages, from client's aspect.

Dependencies's performance

The libraries this project depends to, are not being maintained for a while, there are some performance tweaks can be done.

For example, the packing processes of DNS packet in dnsd, gets improved to 3x faster due to commit:

- Original x 4,172 ops/sec ±1.49% (82 runs sampled)
+ indexOf & substring x 11,699 ops/sec ±1.06% (84 runs sampled)
+ Buffer.from x 11,663 ops/sec ±1.17% (81 runs sampled)
+ Body Buffer x 12,691 ops/sec ±1.11% (84 runs sampled)

fwdns's People

Contributors

yyfrankyy avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.