table creation, random data and need some more stuff
authorPaul J R <me@pjr.cc>
Sun, 15 Nov 2009 15:30:03 +0000 (02:30 +1100)
committerPaul J R <me@pjr.cc>
Sun, 15 Nov 2009 15:30:03 +0000 (02:30 +1100)
src/benchcontroller.go
src/dbconnector.go
src/makeit [changed mode: 0755->0644]
src/webconnector.go

index 5370173..21150e1 100644 (file)
@@ -3,9 +3,8 @@
 package benchcontroller
 
 import (
-       //"./dbconnector";
+       "./dbconnector";
        "fmt";
-       "time";
        "strings";
        "strconv";
        "os";
@@ -32,7 +31,6 @@ func CreateController()(contConfig *BenchControllerConfig)
 func MainLoop(conf *BenchControllerConfig, commInChan chan string, commOutChan chan string)
 {
        for {
-               time.Sleep(1000000000);
                i := <-commInChan;
                
                fmt.Printf("coms: %s\n", i);
@@ -62,9 +60,26 @@ func MainLoop(conf *BenchControllerConfig, commInChan chan string, commOutChan c
                                conf.dbpass = calls[4];
                                conf.dbname = calls[5];
                                
-                       case "asdf":
+                       case "begin":
                                // get ready to bench - start the clients
                                os.Stdout.WriteString("ready clients\n");
+
+                               comchan := make(chan int);
+                               var cont bool;
+                               
+                               
+                               go dbconnector.DBSetup("mysql", conf.dbhost, conf.dbuser, conf.dbpass, conf.dbname, conf.datamult, comchan);
+                               cont=true;
+                                
+                               for cont{
+                                       val := <- comchan;
+                                       fmt.Printf("val: %d\n", val);
+                                       if val == 100 {
+                                                cont = false;
+                                       }
+                               }
+                               
+                               os.Stdout.WriteString("ok, im done\n");
                        case "qwer":
                                // start the clients
                                os.Stdout.WriteString("start clients\n");
index e09ebe9..83dc649 100644 (file)
@@ -1,10 +1,39 @@
 // um yes... its a db connector
 package dbconnector
 
+import (
+       "./dbibridge";
+       "time";
+       "rand";
+)
+
 type DBConnector struct {
        // err, yes
 }
 
+
+func CreateRandomText(len int) (str string)
+{
+       buf := make([]byte, len+2);
+
+       rand.Seed(time.Nanoseconds());
+       
+       for i:=0; i<len; i++ {
+               switch(rand.Int()%3) {
+                case 0:
+                    buf[i] = uint8(rand.Int()%26+65);
+                case 1:
+                    buf[i] = uint8(rand.Int()%26+97);
+                case 2:
+                    buf[i] = uint8(rand.Int()%10+48);
+        }
+        buf[i+1] = 0;
+               
+       }
+       
+       return string(buf);
+}
+
 func DBSetup(dbtype string, host string, username string, password string, database string, datamult int, comout chan int)
 {
 
@@ -16,40 +45,49 @@ func DBSetup(dbtype string, host string, username string, password string, datab
        dbibridge.DBIConnect(Dbconn, "mysql", host, username, password, database);
        
        if dbtype == "mysql" {
-               dbibridge.ExecSQL("create table WAREHOUSE (
-               W_ID integer NOT NULL,
-               W_NAME CHARACTER(10),
-               W_STREET_1 CHARACTER(20),
-               W_STREET_2 CHARACTER(20),
-               W_CITY CHARACTER(20),
-               W_STATE CHARACTER(2),
-               W_ZIP CHARACTER(9),
-               W_TAX integer,
-               W_YTD integer,
+               dbibridge.ExecSQL(Dbconn,"create table WAREHOUSE ( \
+               W_ID integer NOT NULL, \
+               W_NAME CHARACTER(10), \
+               W_STREET_1 CHARACTER(20), \
+               W_STREET_2 CHARACTER(20), \
+               W_CITY CHARACTER(20), \
+               W_STATE CHARACTER(2), \
+               W_ZIP CHARACTER(9), \
+               W_TAX integer, \
+               W_YTD integer, \
                PRIMARY KEY(W_ID))");
 
-               dbibridge.ExecSQL("create table DISTRICT (
-               D_ID integer NOT NULL,
-               D_W_ID integer NOT NULL,
-               D_NAME CHARACTER(10),
-               D_STREET_1 CHARACTER(20),
-               D_STREET_2 CHARACTER(20),
-               D_CITY CHARACTER(20),
-               D_STATE CHARACTER(2),
-               D_ZIP CHARACTER(9),
-               D_TAX integer,
-               D_YTD integer,
-               D_NEXT_O_ID integer,
+               dbibridge.ExecSQL(Dbconn,"create table DISTRICT ( \
+               D_ID integer NOT NULL, \
+               D_W_ID integer NOT NULL, \
+               D_NAME CHARACTER(10), \
+               D_STREET_1 CHARACTER(20), \
+               D_STREET_2 CHARACTER(20), \
+               D_CITY CHARACTER(20), \
+               D_STATE CHARACTER(2), \
+               D_ZIP CHARACTER(9), \
+               D_TAX integer, \
+               D_YTD integer, \
+               D_NEXT_O_ID integer, \
                PRIMARY KEY(D_W_ID, D_ID))");
                
-               dbibridge.ExecSQL("create table ITEM (
-               I_ID integer NOT NULL,
-               I_IM_ID integer,
-               I_NAME CHARACTER(24),
-               I_PRICE integer,
-               I_DATA CHARACTER(50),
+               dbibridge.ExecSQL(Dbconn,"create table ITEM ( \
+               I_ID integer NOT NULL, \
+               I_IM_ID integer, \
+               I_NAME CHARACTER(24), \
+               I_PRICE integer, \
+               I_DATA CHARACTER(50), \
                PRIMARY KEY(I_ID))");           
        }
+       
+       for i := 1; i < 100; i += 10 {
+               time.Sleep(1000000000);
+               comout <- i;
+       }
+       comout <- 100;
+       
+       // now we need to actually create data in the tables...
+       
 
        dbibridge.DBIDisconnect(Dbconn);
 }
old mode 100755 (executable)
new mode 100644 (file)
index 2916e16..b7fac86
@@ -9,9 +9,10 @@ gcc -m32 -fPIC -O2 -o dbibridge.cgo4.o -c  dbibridge.cgo4.c
 gcc -m32 -shared -L`pwd` -lpthread -lm -ldbi -o dbibridge_dbibridge.so dbibridge.cgo4.o 
 cp dbibridge_dbibridge.so /export/src/external/golang//pkg/linux_386/./dbibridge_dbibridge.so
 
-8g benchcontroller.go
 
 
 
+8g dbconnector.go
+8g benchcontroller.go
 8g -I. webconnector.go
 8l -o godhammer -L. webconnector.8
index de43ec6..e7436d3 100644 (file)
@@ -8,6 +8,7 @@ import (
        "io";
        //"./dbibridge";
        "./benchcontroller";
+       //"dbconnector";
        "fmt";
 )
 
@@ -50,6 +51,7 @@ func beginPage(c *http.Conn, req *http.Request)
                //dbname := req.FormValue("dbname");
                //nthreads := req.FormValue("nthreads");
                //dbmult := req.FormValue("dbmult");
+               comout <- "begin:setup";
                
                footer(c);
        }
@@ -129,6 +131,7 @@ func main()
        comin = make(chan string);
        comout = make(chan string);
        
+       
        bc := benchcontroller.CreateController();
        go benchcontroller.MainLoop(bc, comout, comin);