| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package main
- import (
- "encoding/json"
- "fmt"
- "math/rand"
- "os"
- "git.wecise.com/wecise/odb-go/odb"
- "git.wecise.com/wecise/odb-go/odbc"
- "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 := os.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)
- }
- }
- logger.SetConsole(true)
- // 根据参数配置获取 ODBC 连接
- // 参数设置为程序默认配置
- // 可以通过命令行,环境变量 或 与应用同名的.conf配置文件 设置
- // 远程连接需要在白名单中增加本地IP
- odbc := odbc.ODBC(&odb.Config{
- Hosts: []string{"47.92.151.165:11001"},
- Keyspace: conf.Keyspace,
- User: fmt.Sprint("测试客户端"),
- Pass: "********",
- PoolSize: 20,
- Debug: true,
- })
- // 结束前关闭 ODBC 连接
- defer odbc.Close()
- /* _, err := odbc.Query( conf.Schema ).Do()
- if err != nil {
- logger.Info("Query error:" + err.Error())
- return
- }*/
- mql1 := `insert into c14490 (id, name) values (?, ? )`
- count_1 := int(450 * conf.Rate)
- for i := 0; i < count_1; i++ {
- _, err := odbc.Query(mql1, fmt.Sprintf("c14490:c%d", i), fmt.Sprintf("c14490_%d", i)).Do()
- if err != nil {
- logger.Errorf("%v", err)
- return
- }
- }
- mql2 := `insert into c14409 (id, name) values (?, ? )`
- count_2 := int(24000 * conf.Rate)
- for i := 0; i < count_2; i++ {
- _, err := odbc.Query(mql2, fmt.Sprintf("c14409:c%d", i), fmt.Sprintf("c14409_%d", i)).Do()
- if err != nil {
- logger.Errorf("%v", err)
- return
- }
- }
- mql3 := `insert into c19900 (id, name) values (?, ? )`
- count_3 := int(120000 * conf.Rate)
- for i := 0; i < count_3; i++ {
- _, err := odbc.Query(mql3, fmt.Sprintf("c19900:c%d", i), fmt.Sprintf("c19900_%d", i)).Do()
- if err != nil {
- logger.Errorf("%v", err)
- return
- }
- }
- mql4 := `insert into cnode (id, name) values (?, ? )`
- count_c := int(500000 * conf.Rate)
- for i := 0; i < count_c; i++ {
- _, err := odbc.Query(mql4, fmt.Sprintf("cnode:c%d", i), fmt.Sprintf("cnode_%d", i)).Do()
- if err != nil {
- logger.Errorf("%v", err)
- return
- }
- }
- mql5 := `insert into cnode (id, name) values (?, ? )`
- count_t := int(120000 * conf.Rate)
- for i := 0; i < count_t; i++ {
- _, err := odbc.Query(mql5, fmt.Sprintf("tnode:c%d", i), fmt.Sprintf("tnode_%d", i)).Do()
- 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 := odbc.Query(fmt.Sprintf(`create ('c14490:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('c14409:c%d')`, i, from, to, todevice)).Do()
- 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 := odbc.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)).Do()
- 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 := odbc.Query(fmt.Sprintf(`create ('c14409:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('c19900:c%d')`, i, from, to, todevice)).Do()
- 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 := odbc.Query(fmt.Sprintf(`create ('c19900:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('cnode:c%d')`, i, from, to, todevice)).Do()
- if err != nil {
- logger.Errorf("%v", err)
- return
- }
- todevice = i % count_t
- _, err = odbc.Query(fmt.Sprintf(`create ('c19900:c%d')-[:connect{"from":"GigabitEthernet%d","to":"GigabitEthernet%d"}]->('tnode:c%d')`, i, from, to, todevice)).Do()
- if err != nil {
- logger.Errorf("%v", err)
- return
- }
- }
- }
|