sony/sonyflake: A distributed unique ID generator ... - GitHub
文章推薦指數: 80 %
Sonyflake is a distributed unique ID generator inspired by Twitter's Snowflake. Sonyflake focuses on lifetime and performance on many host/core environment. So ... Skiptocontent {{message}} sony / sonyflake Public Notifications Fork 233 Star 2.6k AdistributeduniqueIDgeneratorinspiredbyTwitter'sSnowflake License MITlicense 2.6k stars 233 forks Star Notifications Code Issues 2 Pullrequests 5 Actions Projects 0 Wiki Security Insights More Code Issues Pullrequests Actions Projects Wiki Security Insights Thiscommitdoesnotbelongtoanybranchonthisrepository,andmaybelongtoaforkoutsideoftherepository. master Branches Tags Couldnotloadbranches Nothingtoshow {{refName}} default Couldnotloadtags Nothingtoshow {{refName}} default 1 branch 1 tag Code Latestcommit osamingo Maketestingsimple(#20) … 848d664 Aug27,2020 Maketestingsimple(#20) *Maketestingsimpler *Removetestingdeps *Simplemizetests 848d664 Gitstats 22 commits Files Permalink Failedtoloadlatestcommitinformation. Type Name Latestcommitmessage Committime awsutil Fixineffassignerror May29,2016 example Initialcommit Jun1,2015 .gitignore Initialcommit Jun1,2015 .travis.yml SetGostableversions Aug10,2020 LICENSE Initialcommit Jun1,2015 README.md UpdateREADME.md Oct7,2019 go.mod Maketestingsimple(#20) Aug27,2020 go.sum Maketestingsimple(#20) Aug27,2020 sonyflake.go Initialcommit Jun1,2015 sonyflake_test.go Maketestingsimple(#20) Aug27,2020 Viewcode Sonyflake Installation Usage AWSVPCandDocker License README.md Sonyflake SonyflakeisadistributeduniqueIDgeneratorinspiredbyTwitter'sSnowflake. Sonyflakefocusesonlifetimeandperformanceonmanyhost/coreenvironment. SoithasadifferentbitassignmentfromSnowflake. ASonyflakeIDiscomposedof 39bitsfortimeinunitsof10msec 8bitsforasequencenumber 16bitsforamachineid Asaresult,Sonyflakehasthefollowingadvantagesanddisadvantages: Thelifetime(174years)islongerthanthatofSnowflake(69years) Itcanworkinmoredistributedmachines(2^16)thanSnowflake(2^10) Itcangenerate2^8IDsper10msecatmostinasinglemachine/thread(slowerthanSnowflake) However,ifyouwantmoregenerationrateinasinglehost, youcaneasilyrunmultipleSonyflakeIDgeneratorsconcurrentlyusinggoroutines. Installation gogetgithub.com/sony/sonyflake Usage ThefunctionNewSonyflakecreatesanewSonyflakeinstance. funcNewSonyflake(stSettings)*Sonyflake YoucanconfigureSonyflakebythestructSettings: typeSettingsstruct{ StartTimetime.Time MachineIDfunc()(uint16,error) CheckMachineIDfunc(uint16)bool } StartTimeisthetimesincewhichtheSonyflaketimeisdefinedastheelapsedtime. IfStartTimeis0,thestarttimeoftheSonyflakeissetto"2014-09-0100:00:00+0000UTC". IfStartTimeisaheadofthecurrenttime,Sonyflakeisnotcreated. MachineIDreturnstheuniqueIDoftheSonyflakeinstance. IfMachineIDreturnsanerror,Sonyflakeisnotcreated. IfMachineIDisnil,defaultMachineIDisused. DefaultMachineIDreturnsthelower16bitsoftheprivateIPaddress. CheckMachineIDvalidatestheuniquenessofthemachineID. IfCheckMachineIDreturnsfalse,Sonyflakeisnotcreated. IfCheckMachineIDisnil,novalidationisdone. InordertogetanewuniqueID,youjusthavetocallthemethodNextID. func(sf*Sonyflake)NextID()(uint64,error) NextIDcancontinuetogenerateIDsforabout174yearsfromStartTime. ButaftertheSonyflaketimeisoverthelimit,NextIDreturnsanerror. AWSVPCandDocker Theawsutilpackageprovides thefunctionAmazonEC2MachineIDthatreturnsthelower16-bitprivateIPaddressoftheAmazonEC2instance. ItalsoworkscorrectlyonDocker byretrievinginstancemetadata. AWSVPC isassignedasingleCIDRwithanetmaskbetween/28and/16. SoifeachEC2instancehasauniqueprivateIPaddressinAWSVPC, thelower16bitsoftheaddressisalsounique. Inthiscommoncase,youcanuseAmazonEC2MachineIDasSettings.MachineID. SeeexamplethatrunsSonyflakeonAWSElasticBeanstalk. License TheMITLicense(MIT) SeeLICENSEfordetails. About AdistributeduniqueIDgeneratorinspiredbyTwitter'sSnowflake Topics golang id-generator Resources Readme License MITlicense Stars 2.6k stars Watchers 51 watching Forks 233 forks Releases 1 tags Packages0 Nopackagespublished Usedby795 +787 Contributors4 YoshiyukiMineo YoshiyukiMineo osamingo OsamuTONOMORI yuokada YukihiroOkada(Yuki) golint-fixer golintfixer Languages Go 98.6% Other 1.4% Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.
延伸文章資訊
- 1twitter-snowflake · GitHub Topics
Twitter Snowflake-alike ID generator for .Net ... A distributed id generation solution based on z...
- 2A .NET port of Twitter Snowflake ID generation algorithm.
移植 Snowflake 的 ID 生成算法。有关该算法的详情,请参阅. /// https://github.com/twitter/snowflake/tree/snowflake-2010...
- 3Snowflake algorithm (improved version) - Programmer Group
- 4twitter-archive/snowflake - GitHub
GitHub - twitter-archive/snowflake: Snowflake is a network service for generating unique ID numbe...
- 5sony/sonyflake: A distributed unique ID generator ... - GitHub
Sonyflake is a distributed unique ID generator inspired by Twitter's Snowflake. Sonyflake focuses...