[ANN] A fault-tolerant network service for meaningful GUID generation (in Go)

187 views
Skip to first unread message

bmizerany

unread,
Nov 29, 2011, 2:52:45 PM11/29/11
to golan...@googlegroups.com
It's amazing how quickly Go allows me to produce so many useful, yet efficient things, so quickly, with little to no dependencies, and even less code.

Sanjay Menakuru

unread,
Nov 29, 2011, 7:12:14 PM11/29/11
to golan...@googlegroups.com
nice! pretty cool. 

one nit...

i think line 27 of https://github.com/bmizerany/noeq.go/blob/master/client.go should read n := rand.Intn(len(c.addrs))

according to documentation of rand.Intn (http://weekly.golang.org/pkg/math/rand/#Intn) its inclusive 0, exclusive of the number provided, so with the code you have now, it would never pick the last server in the list.

i could be completely mistaken however.


either way, its a testament to go's succinctness how 'welcoming' the source of this program is, considering the relatively difficult problem its solving.
Sanjay

bmizerany

unread,
Nov 29, 2011, 7:33:33 PM11/29/11
to golan...@googlegroups.com
Great catch. Thank you. Fixed.

Sanjay Menakuru

unread,
Nov 29, 2011, 9:22:44 PM11/29/11
to golan...@googlegroups.com
Also, one other thing.

You should call rand.Seed(time.Nanoseconds()) before you call the random function at all. if you look at http://weekly.golang.org/src/pkg/math/rand/rand.go?s=2823:2879#L108, they initialize the global seed to a constant of 1. so while a number gotten from rand will be pseudorandom compared to the next number from rand, the sequence of numbers from rand will be consistent for each run of the program. minimal program with which to show this can be found here: http://play.golang.org/p/q9usKyf67a
You have to run this on your machine as time.Nanoseconds() always return the same value on Google servers. Try it commenting out the seed line and run it a few times.

Sanjay

bmizerany

unread,
Nov 29, 2011, 10:48:22 PM11/29/11
to golan...@googlegroups.com
Right. I'm not sure how I feel about a library setting the global seed. I think this should be a documentation issue then, or I should use crypto/rand.

Evan Shaw

unread,
Nov 29, 2011, 11:27:52 PM11/29/11
to golan...@googlegroups.com

You could just not use the global rand.Rand object. Create your own
with rand.New and do what you want with it.

- Evan

Sanjay Menakuru

unread,
Nov 30, 2011, 1:17:53 AM11/30/11
to golan...@googlegroups.com
Yea, I was just trying to give a minimalistic solution. I normally use "rg := rand.New(rand.NewSource(*seed))", where seed is an int64 commandline flag that defaults to time.Nanoseconds(). This lets me get deterministic behaviour if I want, or by default true (pseudo) randomness.

Although I do agree that its weird that the global seed is a constant.

Sanjay

Maxim Pimenov

unread,
Nov 30, 2011, 3:50:35 AM11/30/11
to golan...@googlegroups.com
$ cd $GOROOT/src/pkg/github.com/bmizerany/noeq.go
$ gotest

6g   -p github.com/bmizerany/noeq.go -o _gotest_.6 client.go  bench_test.go client_test.go example_test.go
client_test.go:4: can't find import: "github.com/bmizerany/assert"
make: *** [_gotest_.6] Error 1




Also, after "goinstall github.com/bmizerany/assert" is still fails:

--- FAIL: noeq.TestClientGen (0.00 seconds)
client_test.go:14: dial tcp 127.0.0.1:4444: connection refused
2011/11/30 12:47:17 ERROR: dial tcp 127.0.0.1:4444: connection refused
2011/11/30 12:47:17 ERROR: dial tcp 127.0.0.1:4444: connection refused
2011/11/30 12:47:17 ERROR: dial tcp 127.0.0.1:4444: connection refused
2011/11/30 12:47:17 FATAL: unable to connect to weiqid
gotest: "./6.out" failed: exit status 1



And the idea to keep *.6 files and binaries in your goinstallable repo seems bad to me.

wkharold

unread,
Dec 1, 2011, 3:00:07 PM12/1/11
to golang-nuts
noeq is just a client. For it to work you need a server. That would be
noeqd - https://github.com/bmizerany/noeqd.git

... WkH

bmizerany

unread,
Dec 1, 2011, 5:31:19 PM12/1/11
to golan...@googlegroups.com
I'm sorry about that. I've updated the README. It should have been linking/referencing noeqd, not noeq.
Reply all
Reply to author
Forward
0 new messages