All Projects → ruoshan → lua-resty-jump-consistent-hash

ruoshan / lua-resty-jump-consistent-hash

Licence: MIT License
consistent hash for openresty

Programming Languages

perl
6916 projects
lua
6591 projects
c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to lua-resty-jump-consistent-hash

Lua Cassandra
Pure Lua driver for Apache Cassandra
Stars: ✭ 95 (+295.83%)
Mutual labels:  luajit, openresty
nott
The New OTT Platform - an excuse to discuss and design a simple edge computing platform
Stars: ✭ 46 (+91.67%)
Mutual labels:  luajit, openresty
Lua Resty Http
Lua HTTP client cosocket driver for OpenResty / ngx_lua.
Stars: ✭ 1,647 (+6762.5%)
Mutual labels:  luajit, openresty
cdn-up-and-running
CDN Up and Running - an introduction about how modern CDNs works
Stars: ✭ 131 (+445.83%)
Mutual labels:  luajit, openresty
phi
an api-gateway based on openresty
Stars: ✭ 23 (-4.17%)
Mutual labels:  luajit, openresty
Vanilla
An OpenResty Lua MVC Web Framework
Stars: ✭ 1,018 (+4141.67%)
Mutual labels:  luajit, openresty
Api Umbrella
Open source API management platform
Stars: ✭ 1,735 (+7129.17%)
Mutual labels:  luajit, openresty
Apioak
Full Lifecycle Management API Gateway.
Stars: ✭ 335 (+1295.83%)
Mutual labels:  luajit, openresty
Lua Resty Redis Connector
Connection utilities for lua-resty-redis
Stars: ✭ 186 (+675%)
Mutual labels:  luajit, openresty
Lua Resty Jit Uuid
Fast and dependency-free UUID library for LuaJIT/ngx_lua
Stars: ✭ 169 (+604.17%)
Mutual labels:  luajit, openresty
Lua Resty Post
HTTP post utility for openresty
Stars: ✭ 30 (+25%)
Mutual labels:  luajit, openresty
lua-resty-ipcidr
A simple and very fast function to check against CIDR
Stars: ✭ 17 (-29.17%)
Mutual labels:  luajit, openresty
Lua Nginx Redis
🌺 Redis、Lua、Nginx、OpenResty 笔记和资料
Stars: ✭ 757 (+3054.17%)
Mutual labels:  luajit, openresty
Lua Resty Route
URL Routing Library for OpenResty Supporting Pluggable Matching Engines
Stars: ✭ 88 (+266.67%)
Mutual labels:  luajit, openresty
Ledge
An RFC compliant and ESI capable HTTP cache for Nginx / OpenResty, backed by Redis
Stars: ✭ 412 (+1616.67%)
Mutual labels:  luajit, openresty
Motan Openresty
A cross-language RPC framework for rapid development of high performance distributed services based on OpenResty.
Stars: ✭ 117 (+387.5%)
Mutual labels:  luajit, openresty
Lua Resty Mlcache
Layered caching library for OpenResty
Stars: ✭ 274 (+1041.67%)
Mutual labels:  luajit, openresty
Luajit.io
luajit io framework
Stars: ✭ 277 (+1054.17%)
Mutual labels:  luajit, openresty
Lua Resty Repl
Interactive console (REPL) for Openresty and luajit code
Stars: ✭ 165 (+587.5%)
Mutual labels:  luajit, openresty
nginx-lua
Nginx 1.19+ with LUA support based on Alpine Linux, Amazon Linux, Debian, Fedora and Ubuntu.
Stars: ✭ 112 (+366.67%)
Mutual labels:  luajit, openresty

Jump Consisten Hash for luajit

A simple implementation of this paper.

Features

  • small memory footprint and fast
  • consistence is maintained through servers' updating

Installation

make
make PREFIX=/usr/local/openresty install

Usage

  • you can use the basic jchash module to do consistent-hash
local jchash = require "resty.chash.jchash"

local buckets = 8
local id = jchash.hash_short_str("random key", buckets)
  • or you can use the wrapping module resty.chash.server to consistent-hash a list of servers
local jchash_server = require "resty.chash.server"

local my_servers = {
    { "127.0.0.1", 80, 1},   -- {addr, port, weight} weight can be left out if it's 1
    { "127.0.0.2", 80 },
    { "127.0.0.3", 80 }
}

local cs, err = jchash_server.new(my_servers)
local uri = ngx.var.uri
local svr = cs:lookup(uri)
local addr = svr[1]
local port = svr[2]

-- now you can use the ngx.balancer to do some consistent LB

-- you can even update the servers list, and still maintain the consistence, eg.
local my_new_servers = {
    { "127.0.0.2", 80 },
    { "127.0.0.3", 80 },
    { "127.0.0.4", 80 }
}

cs:update_servers(my_new_servers)
svr = cs:lookup(uri)   -- if the server was 127.0.0.2, then it stays the same,
                       -- as we only update the 127.0.0.4.

-- what's more, consistence is maintained even the number of servers changes! eg.
local my_less_servers = {
    { "127.0.0.2", 80 },
    { "127.0.0.3", 80 }
}
cs:update_servers(my_less_servers)
svr = cs:lookup(uri)   -- if the server was 127.0.0.2, then it stays the same,
                       -- if the server was 127.0.0.4, then it has 50% chance to be
                       -- 127.0.0.2 or 127.0.0.3

cs:update_servers(my_new_servers)
svr = cs:lookup(uri)   -- if the server was 127.0.0.2, then it has 66% chance to stay the same

Todo

  • weight for the servers list [done]
  • Test::Nginx [done]

Test

make test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].