hash con MD5
bulk size 300
This commit is contained in:
parent
8bfe81d573
commit
fad6c36c94
3 changed files with 22 additions and 4 deletions
22
consumer.go
22
consumer.go
|
@ -2,6 +2,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -19,7 +21,7 @@ type consumed struct {
|
||||||
logins []string
|
logins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func hash(val []byte) string {
|
func hash256(val []byte) string {
|
||||||
|
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write(val)
|
h.Write(val)
|
||||||
|
@ -27,6 +29,22 @@ func hash(val []byte) string {
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
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() {
|
func consumer() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -46,7 +64,7 @@ func consumer() {
|
||||||
bulk.Unordered()
|
bulk.Unordered()
|
||||||
|
|
||||||
for p := range prod {
|
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{
|
mquota := MongoQuota{
|
||||||
ID: mlID,
|
ID: mlID,
|
||||||
User: prod[p].user,
|
User: prod[p].user,
|
||||||
|
|
2
main.go
2
main.go
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_Version = "v2.2.2"
|
_Version = "v2.3.0"
|
||||||
_Producer = 0
|
_Producer = 0
|
||||||
_Consumer = 1
|
_Consumer = 1
|
||||||
)
|
)
|
||||||
|
|
|
@ -70,6 +70,6 @@ func init() {
|
||||||
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
|
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
|
||||||
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
||||||
flag.BoolVar(&opts.Test, "DD", false, "Test")
|
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")
|
flag.IntVar(&opts.Queue, "q", 2, "parallel consumer")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue