Created
July 19, 2018 05:13
-
-
Save linxGnu/66ab7ecf3f4e8480874734e9fe08165d to your computer and use it in GitHub Desktop.
M3DB Standalone - Write Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"sync" | |
"time" | |
"github.com/m3db/m3db/src/dbnode/client" | |
"github.com/m3db/m3db/src/dbnode/sharding" | |
topo "github.com/m3db/m3db/src/dbnode/topology" | |
"github.com/m3db/m3x/ident" | |
xtime "github.com/m3db/m3x/time" | |
) | |
const ( | |
numberServer = 64 | |
numberRegion = 2 | |
factorDegree = 1024 | |
) | |
func main() { | |
start := time.Now() | |
bench() | |
d := time.Now().Sub(start).Seconds() | |
t := numberServer * numberRegion * factorDegree | |
fmt.Printf("%d %.3f %.3f\n", t, d, float64(t)/d) | |
} | |
func bench() { | |
shardIDs := make([]uint32, 64) | |
for i := range shardIDs { | |
shardIDs[i] = uint32(i) | |
} | |
shards := sharding.NewShards(shardIDs, 2) | |
fn := sharding.NewHashFn(len(shards), 1313) | |
shardSet, _ := sharding.NewShardSet(shards, fn) | |
hss := topo.NewHostShardSet(topo.NewHost("1", "127.0.0.1:9000"), shardSet) | |
tplogyOptions := topo.NewStaticOptions().SetReplicas(1).SetHostShardSets([]topo.HostShardSet{hss}).SetShardSet(shardSet) | |
tplogy := topo.NewStaticInitializer(tplogyOptions) | |
options := client.NewOptions().SetTopologyInitializer(tplogy).SetWriteConsistencyLevel(topo.ConsistencyLevelOne) | |
c, err := client.NewClient(options) | |
if err != nil { | |
log.Fatal(err) | |
} | |
session, err := c.NewSession() | |
if err != nil { | |
panic(err) | |
} | |
defer session.Close() | |
var wg sync.WaitGroup | |
for i := 0; i < numberServer; i++ { | |
wg.Add(1) | |
go func(serverID int) { | |
for region := 0; region < numberRegion; region++ { | |
tags := ident.NewTags( | |
ident.StringTag("server", fmt.Sprintf("Server%d", serverID)), | |
ident.StringTag("region", fmt.Sprintf("Region%d", region)), | |
) | |
for factor := 0; factor < factorDegree; factor++ { | |
if err := session.WriteTagged( | |
ident.StringID("default"), | |
ident.StringID("cpu"), | |
ident.NewTagsIterator(tags), | |
time.Now(), float64(1+serverID*factor*region), | |
xtime.Second, nil); err != nil { | |
panic(err) | |
} | |
} | |
} | |
wg.Done() | |
}(i) | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment