Coder Social home page Coder Social logo

fastid's Introduction

FastID -- Snowflake ID generating in Go

Godoc Go Report Card Build Status codecov

FastID is a pluggable unique ID generator in Go.

  • Under 64 bits (Long Integer)
  • K-Ordered
  • Lock-free (using atomic CAS)
  • Decentralized

Installation

go get github.com/beinan/fastid

Quick Start

Generate an ID

import (
  "fmt"
  "github.com/beinan/fastid"
)

func ExampleGenInt64ID() {
  id := fastid.CommonConfig.GenInt64ID()
  fmt.Printf("id generated: %v", id)
}

Recommended Settings

  • 40 bits timestamp (34 years from 2018-06-01)
  • 16 bits machine ID (using lower 16 bits of IP v4 addr as default)
  • 7 bits sequence number

With this setting, FastID is able to generate 128(2^7) unique IDs per millisecond (1.048576 millisecond, 2^10 nanosecond).

Customized Settings

See the examples in GoDoc

Benchmarks

Benchmark Settings

  • 40 bits timestamp (34 years from 2018-06-01)
  • 8 bits machine ID
  • 15 bits sequence number
go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/beinan/fastid
BenchmarkGenID-4        20000000                79.7 ns/op
BenchmarkGenIDP-4       20000000               141 ns/op
PASS
ok      github.com/beinan/fastid        4.779s

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.