hash con MD5

bulk size 300
This commit is contained in:
Michele 2017-08-21 10:27:49 +02:00
parent 8bfe81d573
commit fad6c36c94
3 changed files with 22 additions and 4 deletions

View file

@ -2,6 +2,8 @@
package main
import (
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"fmt"
@ -19,7 +21,7 @@ type consumed struct {
logins []string
}
func hash(val []byte) string {
func hash256(val []byte) string {
h := sha256.New()
h.Write(val)
@ -27,6 +29,22 @@ func hash(val []byte) string {
return hex.EncodeToString(h.Sum(nil))
}
func hash160(val []byte) string {
h := sha1.New()
h.Write(val)
return hex.EncodeToString(h.Sum(nil))
}
func hash128(val []byte) string {
h := md5.New()
h.Write(val)
return hex.EncodeToString(h.Sum(nil))
}
func consumer() {
for {
@ -46,7 +64,7 @@ func consumer() {
bulk.Unordered()
for p := range prod {
mlID := hash([]byte(fmt.Sprintf("%s%s", prod[p].user, start.Format("20060102T15"))))
mlID := hash128([]byte(fmt.Sprintf("%s%s", prod[p].user, start.Format("20060102T15"))))
mquota := MongoQuota{
ID: mlID,
User: prod[p].user,

View file

@ -12,7 +12,7 @@ import (
)
const (
_Version = "v2.2.2"
_Version = "v2.3.0"
_Producer = 0
_Consumer = 1
)

View file

@ -70,6 +70,6 @@ func init() {
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
flag.BoolVar(&opts.Debug, "D", false, "Debug")
flag.BoolVar(&opts.Test, "DD", false, "Test")
flag.IntVar(&opts.MaxBulk, "M", 500, "Max Mongodb bulk")
flag.IntVar(&opts.MaxBulk, "M", 300, "Max Mongodb bulk")
flag.IntVar(&opts.Queue, "q", 2, "parallel consumer")
}