Giter Club home page Giter Club logo

jchash's Introduction

jchash

CI

Jump Consistent Hash NIF library for Erlang/Elixir.

This NIF implements the Jump Consistent Hash algorithm, created by John Lamping and Eric Veach developed at Google, Inc. This is the original paper: "A Fast, Minimal Memory, Consistent Hash Algorithm".

Installation

Erlang

In your rebar.config:

{deps, [
  {jchash, "0.1.3"}
]}.

Usage example:

> jchash:compute(1, 2).
0

> jchash:compute(erlang:phash2(os:timestamp()), 100).
22

Elixir

In your mix.exs:

def deps do
  [{:jchash, "~> 0.1"}]
end

Usage example:

> :jchash.compute(1, 2)
0

> System.system_time() |> :erlang.phash2() |> :jchash.compute(100)
22

Testing

$ rebar3 eunit

Copyright and License

Copyright (c) 2016 Carlos Andres Bolaños R.A.

jchash source code is licensed under the MIT License.

jchash's People

Contributors

cabol avatar nikolaik avatar xpgdk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jchash's Issues

Unable to build under MacOS Mojave

I'm getting the following error when trying to build the dependency:


===> Compiling jchash
cc /Users/username/projects/company/enterprise/deps/jchash/c_src/jchash.o -L/usr/local/opt/libxslt/lib -shared -L /Users/username/.asdf/installs/erlang/21.3/lib/erl_interface-3.11/lib -lerl_interface -lei -o /Users/username/projects/company/enterprise/deps/jchash/c_src/../priv/jchash.so
Undefined symbols for architecture x86_64:
  "_enif_get_uint", referenced from:
      _compute in jchash.o
  "_enif_get_ulong", referenced from:
      _compute in jchash.o
  "_enif_make_badarg", referenced from:
      _compute in jchash.o
  "_enif_make_int", referenced from:
      _compute in jchash.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/username/projects/company/enterprise/deps/jchash/c_src/../priv/jchash.so] Error 1
===> Hook for compile failed!

** (Mix) Could not compile dependency :jchash, "/Users/username/.asdf/installs/elixir/1.7.4/.mix/rebar3 bare compile --paths "/Users/username/projects/company/enterprise/_build/test/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile jchash", update it with "mix deps.update jchash" or clean it with "mix deps.clean jchash"```

Both erlang and elixir are installed via `asdf`. 

Any suggestion?

Thanks!

Error to use jchash as dependency in Elixir Docker slim image

Hi, @cabol hope you're going well.

I'm using Nebulex with Redis Cluster as backend. I have as a requirement a small docker image size to deploy my application. But, when I use Elixir Docker Slim Image or Elixir Docker Alpine Image I receive an error when Mix tries to compile jchash:

** (Mix) Could not compile dependency :jchash, "/root/.mix/rebar3 bare compile --paths "/upa/_build/prod/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile jchash", update it with "mix deps.update jchash" or clean it with "mix deps.clean jchash"

Versions:

{:jchash, "0.1.1"}
Elixir: 1.8.2
Erlang: 22
{:nebulex, "~> 1.1"},
{:nebulex_redis_adapter, "~> 1.1"}

Can you help me to find which OS dependency I must to install to solve this?

Unable to build with OTP 23

On Ubuntu 20.04 trying to use OTP v23 with jchash i get the following:

$ mix deps.compile jchash
===> Compiling jchash
make: Entering directory '/project/deps/jchash/c_src'
cc -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes -fPIC -I /usr/lib/erlang/erts-11.0.2/include/ -I /usr/lib/erlang/lib/erl_interface-4.0/include  -c -o /project/deps/jchash/c_src/jchash.o /project/deps/jchash/c_src/jchash.c
cc /project/deps/jchash/c_src/jchash.o -shared -L /usr/lib/erlang/lib/erl_interface-4.0/lib -lerl_interface -lei -o /project/deps/jchash/c_src/../priv/jchash.so
/usr/bin/ld: cannot find -lerl_interface
collect2: error: ld returned 1 exit status
make: *** [Makefile:59: /project/deps/jchash/c_src/../priv/jchash.so] Error 1
make: Leaving directory '/project/deps/jchash/c_src'
===> Hook for compile failed!

$ dpkg -l|grep esl-erlang
ii  esl-erlang                                 1:23.0.2-1

Is the deprecation of erl_interface the reason, mentioned here?

Getting on_load_function_failed for :jchash when using nebulex_redis_adapter or nebulex_partitioned_cache on docker

Hi @cabol
Tried setting up a quick application using Nebulex to see how it can be used in our live systems.
I am able to run the application on my local using mix and also using distillery release.
But when I try to create a docker image using elixir:1.9-alpine I get the following error:

2020-06-22 04:17:21.837997 supervisor_report   #{label=>{supervisor,start_error},report=>[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,{on_load_function_failed,jchash}},{offender,[{pid,undefined},{id,kernel_safe_sup},{mfargs,{supervisor,start_link,[{local,kernel_safe_sup},kernel,safe]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}
20#20-06-22 04:17:21.838071 crash_report        {label=>{proc_lib,crash},report=>[[{initial_call,{supervisor,kernel,['Argument__1']}},{pid,<0.990.0>},{registered_name,[]},{error_info,{exit,{on_load_function_failed,jchash},[{init,run_on_load_handlers,0,[]},{kernel,init,1,[{file,"kernel.erl"},{line,189}]},{supervisor,init,1,[{file,"supervisor.erl"},{line,295}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[kernel_sup,<0.965.0>]},{message_queue_len,0},{messages,[]},{links,[<0.967.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,27},{reductions,265}],[]]}
#{label=>{proc_lib,crash},report=>[[{initial_call,{application_master,init,['Argument__1','Argument__2','Argument__3','Argument__4']}},{pid,<0.964.0>},{registered_name,[]},{error_info,{exit,{{shutdown,{failed_to_start_child,kernel_sa2020-06-22 04:17:22.862111 crash_report        fe_sup,{on_load_function_failed,jchash}}},{kernel,start,[normal,[]]}},[{application_master,init,4,[{file,"application_master.erl"},{line,138}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}},{ancestors,[<0.963.0>]},{message_queue_len,1},{messages,[{'EXIT',<0.965.0>,normal}]},{links,[<0.963.0>,<0.961.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,27},{reductions,193}],[]]}
2020-06-22 04:17:22.863361 std_info            #{label=>{application_controller,exit},report=>[{application,kernel},{exited,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,jchash}}},{kernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,jchash}}},{kernel,start,[normal,[]]}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,kernel_safe_sup,{on_load_function_failed,jchash}}},{kernel,start,[normal,[]]}}})

Crash dump is being written to: erl_crash.dump...done

here's the Dockerfile I'm using:

FROM elixir:1.9-alpine

RUN apk update && \
    apk upgrade --no-cache &&\
    apk add --no-cache \
      bash \
      openssl-dev \
      build-base

# Install Hex+Rebar
RUN mix local.hex --force && \
    mix local.rebar --force

WORKDIR /opt/app

ENV MIX_ENV=prod

ADD . .
RUN mix deps.get
RUN mix distillery.release

# Use REPLACE_OS_VARS=true in order to swap runtime env values in rel/vm.args
ENV REPLACE_OS_VARS=true

# Do not use CMD, leads to issues receiving SIGTERM properly
ENTRYPOINT ["_build/prod/rel/nebulex_test_cluster/bin/nebulex_test_cluster", "foreground"]

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.