GUID Global Uniqueness algorithm

Source: Internet
Author: User
Tags nginx server

in the following example, LUA is used to generate the GUID, then compare the MD5 algorithm of Nginx server to compare the efficiency.

functionGUID ()LocalSeed = { '0','1','2','3','4','5','6','7','8','9', 'a','b','C','D','e','F','g','h','I','J', 'k','L','m','N','o','P','Q','R','s','T', 'u','v','W','x','y','Z' } LocalSid ="" forI=1, + DoSid= Sid: seed[Math.random(1, $)] End return String.Format('%s-%s-%s-%s-%s', string.sub(SID,1,8), string.sub(SID,9, A), string.sub(SID, -, -), string.sub(SID, -, -), string.sub(SID, +, +) )EndLocals =0LocalStart =socket.gettime () whiles <100000 Dos=s+1--ngx.Print(Ngx.md5 (Math.random(1, $)) ..'\ r \ n')
Ngx.print (GUID (): ' \ r \ n ')EndNgx.Print("Execute Time:".. Socket.gettime ()-start.'\ r \ n') Ngx.exit ( $)

In the above GUID method, the seed reader can expand itself, for example by adding ' A-Z ' uppercase characters, and the GUID I output with 32 bits,

In the actual testing process, the 100,000-level data generation speed does not consider the write file IO time, far less than 0.4 seconds, and the same amount of ngx.md5 () when the use of a full more than a time;

And then from the uniqueness of the analysis, 100,000 levels of the generated string, tested 10 times, did not find any duplicate string, indicating that the self-matching GUID algorithm sufficient to meet the actual production use;

GUID Global Uniqueness algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.