package main import ( "fmt" "io/ioutil" "os" //"time" //"math" //"strconv" "encoding/json" "math/rand" . "git.wecise.com/wecise/odbserver/odb" "git.wecise.com/wecise/odbserver/odb/test" "gitee.com/wecisecode/util/logger" ) type PerfConfig struct { Schema string `json:"schema"` Rate float64 `json:"rate"` Keyspace string `json:"keyspace"` } func main() { config_file := "config.json" if len(os.Args) >= 2 { config_file = os.Args[1] } conf := &PerfConfig{} if content, err := ioutil.ReadFile(config_file); err != nil { logger.Errorf("read config file : %s, error: %v", config_file, err) } else { if err := json.Unmarshal([]byte(content), conf); err != nil { logger.Errorf("config error: %v", err) } else { logger.Infof("From: %v", conf) } } //options := map[string]interface{} {"cache":odb.CacheAll} //g,err:= odb.New( options ) logger.SetConsole(true) //option := &StoreOption{Cache:CacheAll} option := &Option{Cache: CacheAll, Keyspace: conf.Keyspace, DisableInitialHostLookup: true, DisableNotify: true} g, err := test.NewG(option) if err != nil { logger.Error(err.Error()) } else { defer g.Close() } /* _, _, err = g.Query( conf.Schema ) if err != nil { logger.Info("Query error:" + err.Error()) return }*/ stat, err := g.Prepare(`insert into c14490 (id, name) values (?, ? )`) if err != nil { logger.Errorf("%v", err) return } count_1 := int(450 * conf.Rate) for i := 0; i < count_1; i++ { _, _, err = stat.Exec(fmt.Sprintf("c14490:c%d", i), fmt.Sprintf("c14490_%d", i)) if err != nil { logger.Errorf("%v", err) return } } stat, err = g.Prepare(`insert into c14409 (id, name) values (?, ? )`) if err != nil { logger.Errorf("%v", err) return } count_2 := int(24000 * conf.Rate) for i := 0; i < count_2; i++ { _, _, err = stat.Exec(fmt.Sprintf("c14409:c%d", i), fmt.Sprintf("c14409_%d", i)) if err != nil { logger.Errorf("%v", err) return } } stat, err = g.Prepare(`insert into c19900 (id, name) values (?, ? )`) if err != nil { logger.Errorf("%v", err) return } count_3 := int(120000 * conf.Rate) for i := 0; i < count_3; i++ { _, _, err = stat.Exec(fmt.Sprintf("c19900:c%d", i), fmt.Sprintf("c19900_%d", i)) if err != nil { logger.Errorf("%v", err) return } } stat, err = g.Prepare(`insert into cnode (id, name) values (?, ? )`) if err != nil { logger.Errorf("%v", err) return } count_c := int(500000 * conf.Rate) for i := 0; i < count_c; i++ { _, _, err = stat.Exec(fmt.Sprintf("cnode:c%d", i), fmt.Sprintf("cnode_%d", i)) if err != nil { logger.Errorf("%v", err) return } } stat, err = g.Prepare(`insert into cnode (id, name) values (?, ? )`) if err != nil { logger.Errorf("%v", err) return } count_t := int(120000 * conf.Rate) for i := 0; i < count_t; i++ { _, _, err = stat.Exec(fmt.Sprintf("tnode:c%d", i), fmt.Sprintf("tnode_%d", i)) if err != nil { logger.Errorf("%v", err) return } } //两种连接,每个52 for i := 0; i < count_1; i++ { // connect //{ // "from":"GigabitEthernet1", // "to" :"GigabitEthernet1" //} // connectip //{ // "from":"192.168.1.#11", // "to" :"192.169.1.#11" //} // c14490 ==> 52 ==> c14409 for j := 0; j < 52; j++ { todevice := (j + i) % count_2 from := rand.Intn(999) + 1 to := rand.Intn(100) + 1 _, _, err := g.Query(fmt.Sprintf(`create ('c14490:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('c14409:c%d')`, i, from, to, todevice)) if err != nil { logger.Errorf("%v", err) return } } for j := 0; j < 52; j++ { todevice := (j + i) % count_2 from := rand.Intn(999) + 1 to := rand.Intn(99) + 1 _, _, err := g.Query(fmt.Sprintf(`create ('c14490:c%d')-[:connectip{"from":"192.168.1.%d","to":"192.168.1.%d"}]->('c14409:c%d')`, i, from, to, todevice)) if err != nil { logger.Errorf("%v", err) return } } } //一种连接,每个2个 for i := 0; i < count_2; i++ { for j := 0; j < 2; j++ { todevice := (j + i) % count_3 from := rand.Intn(99) + 1 to := rand.Intn(49) + 1 _, _, err := g.Query(fmt.Sprintf(`create ('c14409:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('c19900:c%d')`, i, from, to, todevice)) if err != nil { logger.Errorf("%v", err) return } } } //一种连接,连接两种设备 for i := 0; i < count_3; i++ { todevice := i % count_c from := rand.Intn(49) + 1 to := rand.Intn(9) + 1 _, _, err := g.Query(fmt.Sprintf(`create ('c19900:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('cnode:c%d')`, i, from, to, todevice)) if err != nil { logger.Errorf("%v", err) return } todevice = i % count_t _, _, err = g.Query(fmt.Sprintf(`create ('c19900:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('tnode:c%d')`, i, from, to, todevice)) if err != nil { logger.Errorf("%v", err) return } } }