JSPM

fast-hashring

1.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 8
    • Score
      100M100P100Q42013F
    • License MIT

    A library for consistent hashing using virtual nodes for improved key distribution.

    Package Exports

    • fast-hashring
    • fast-hashring/consistent-hash.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-hashring) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    fast-hashring

    fast-hashring is a lightweight JavaScript library offering an efficient implementation of consistent hashing using virtual nodes. Designed for high performance, it provides fast and scalable key distribution, ideal for load balancing, caching, and data sharding in distributed systems.

    Installation

    Install via npm:

    npm install fast-hashring

    Or using yarn:

    yarn add fast-hashring

    Usage

    Here’s a basic example of how to integrate fast-hashring into your project:

    import ConsistentHash from 'fast-hashring'
    
    const ch = new ConsistentHash({ virtualNodes: 100 })
    ch.addNode('server1')
    ch.addNode('server2')
    
    const node = ch.getNode('my-key')
    console.log(`Key is assigned to node: ${node}`)

    Features

    • Consistent Hashing with Virtual Nodes:
      Utilizes virtual nodes to distribute keys evenly across real nodes, minimizing load imbalance during node changes.

    • Binary Search for Rapid Lookups:
      Maintains a sorted hash ring of virtual nodes, enabling quick key lookups using an optimized binary search algorithm.

    • High Performance & Scalability:
      The design focuses on speed and efficiency, ensuring low latency and high throughput even with large-scale deployments.

    • Simple & Intuitive API:
      Easy-to-use methods for adding, removing, and retrieving nodes enable quick integration into projects.

    • TypeScript Support:
      Complete TypeScript definitions are provided, offering strong typing and an improved developer experience.

    Why Choose fast-hashring?

    fast-hashring delivers superior performance by leveraging virtual nodes and binary search, providing a more balanced and efficient key distribution compared to traditional hashing methods. Whether you're scaling a distributed cache, load balancer, or sharded database, fast-hashring minimizes remapping and disruption, ensuring high availability and smooth performance.

    Testing

    The library is tested using Bun's testing framework. To run the tests, execute:

    bun test

    License

    MIT