21150e1f459ca0236bfd9ba30f707c33f2f297a2
[goDBhammer.git] / src / benchcontroller.go
1 // the benchmark controller
2
3 package benchcontroller
4
5 import (
6         "./dbconnector";
7         "fmt";
8         "strings";
9         "strconv";
10         "os";
11 )
12
13 type BenchControllerConfig struct {
14         id int;
15         nclients int;
16         datamult int;
17         dbtype string;
18         dbhost string;
19         dbuser string;
20         dbpass string;
21         dbname string;
22 }
23
24 func CreateController()(contConfig *BenchControllerConfig)
25 {
26         bcConfig := new(BenchControllerConfig);
27         
28         return bcConfig;
29 }
30
31 func MainLoop(conf *BenchControllerConfig, commInChan chan string, commOutChan chan string)
32 {
33         for {
34                 i := <-commInChan;
35                 
36                 fmt.Printf("coms: %s\n", i);
37                 
38                 calls := strings.Split(i, ":", 0);
39                 
40                 fmt.Printf("stuff 1: %s, stuff 2: %s\n", calls[0], calls[1]);
41                 
42                 switch calls[0] {
43                         case "configure":
44                                 // this means shutdown
45                                 os.Stdout.WriteString("time for a conf\n");
46                                 conf.id = 0;
47                                 
48                                 
49                                 var esink os.Error;
50                                 
51                                 conf.nclients, esink = strconv.Atoi(calls[7]);
52                                 conf.datamult, esink = strconv.Atoi(calls[6]);
53                                 
54                                 if esink != os.ECHILD {
55                                         // i need to do something with esink or the bollocks compiler screws itself
56                                 }
57                                 conf.dbtype = calls[1];
58                                 conf.dbhost = calls[2];
59                                 conf.dbuser = calls[3];
60                                 conf.dbpass = calls[4];
61                                 conf.dbname = calls[5];
62                                 
63                         case "begin":
64                                 // get ready to bench - start the clients
65                                 os.Stdout.WriteString("ready clients\n");
66
67                                 comchan := make(chan int);
68                                 var cont bool;
69                                 
70                                 
71                                 go dbconnector.DBSetup("mysql", conf.dbhost, conf.dbuser, conf.dbpass, conf.dbname, conf.datamult, comchan);
72                                 cont=true;
73                                  
74                                 for cont{
75                                         val := <- comchan;
76                                         fmt.Printf("val: %d\n", val);
77                                         if val == 100 {
78                                                  cont = false;
79                                         }
80                                 }
81                                 
82                                 os.Stdout.WriteString("ok, im done\n");
83                         case "qwer":
84                                 // start the clients
85                                 os.Stdout.WriteString("start clients\n");
86                 }
87         }
88 }