Code Monkey home page Code Monkey logo

go-jump-consistent-hash's People

Contributors

dependabot[bot] avatar lithammer avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-jump-consistent-hash's Issues

[bug]: The result of hash string is not consistent when running in multiple goroutines

I tested hash "123456789" with fnv.New64a and 2 buckets, the expected res is 0, but in goroutine sometimes res is 1.

func TestHashString(t *testing.T) {
	hasher := New(2, fnv.New64a())
	input := "123456789"
	errCount := make(chan int)
	for i := 0; i < 1000; i++ {
		go func(i int) {
			res := hasher.Hash(input)
			if res != 0 {
				errCount <- 1
				t.Errorf("hash %d error: res is %d", i, res)
			}
		}(i)
	}

	s := 0
	go func() {
		for j := range errCount {
			s += j
		}
	}()

	time.Sleep(1 * time.Second)
	fmt.Println("errCount:", s)
}

I think the HashString function is not goroutine safe.

Concurrency Issue

Really appreciate this library, we use it a lot.

Just wanted to make others aware if you use the examples in highly concurrent code, you will want to create your own unique instance of the hashers rather than the constants in the library as you will get inconsistent results:

Instead of this:
h := jump.HashString("127.0.0.1", 8, jump.CRC64)

You would do this:
h := jump.HashString("127.0.0.1", 8, crc64.New(crc64.MakeTable(crc64.ECMA)))

Just sharing for others.

hash result changed a lot after bucket sized changed

I think the benifit of consistent-hash is this: when bucket size changed, only a litte group of data need rebalanced

so I wrote a program to test this feature, but it shows that every number got remapped

func main(){
    rt := 0
    num := 10000
    for i:=0; i<num; i++{
        var a uint64 = 10000
        i1 := jump.Hash(a, 10)
        i2 := jump.Hash(a, 20)

        if i1 != i2{
            rt++
        }
    }

    fmt.Println(rt == num) // ********* true **********
}

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.