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