Skip to content

Znowflake is an implementation of Twitter's Snowflake using ZeroMQ and C.

Notifications You must be signed in to change notification settings

chelintsien/znowflake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Znowflake

Znowflake is a network service for generating unique 64-bit ID numbers. It's similar to Twitter's Snowflake. Znowflake is implemented in C with ZeroMQ via CZMQ.

Details

Please read the documents for Snowflake. Our motivation and requirements are similar.

There are some differences:

  • Wider machine ID field
  • Epoch at 1337000000 (May 14, 2012)
  • Quits generating unique IDs sooner (good for around 17 years)
  • Relaxed performance and resolution requirements

Usage

Server

Znowflake is a Linux daemon. It might compile on other systems - give it a shot.

It accepts options for port number, machine number, and an option to daemonize. If the port isn't given, it defaults to 23138.

znowflaked -p 5555 -m 7384

This gets a ZMQ_REP socket listening on port 5555.

Configuration File

znowflaked also reads a simple libconfig-based configuration file:

znowflaked -f /etc/znowflaked/znowflaked.conf

Sample configuration file contents:

machine: 2849;
port: 4242;

To daemonize, pass in the -d flag:

znowflaked -d -m 100

Startup Script

An init script for CentOS is found in the znowflaked.sh file. Get the whole thing running:

gcc znowflaked.c -lconfig -lczmq -lzmq -o /usr/local/bin/znowflaked
cp znowflaked.sh /etc/init.d/znowflaked
vi /etc/znowflake/znowflake.conf
service znowflaked start

Start on boot:

chkconfig --add znowflaked
chkconfig znowflaked on

Example Clients

client.c and client.rb show you how to get IDs from the server.

cclient.c is a continuously running client, useful for testing.

cclient -p 1234 -r 1000

grabs IDs from port 1234 at a rate of 1000 per second. Try running multiple instances of cclient.

About

Znowflake is an implementation of Twitter's Snowflake using ZeroMQ and C.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published