diff --git a/client_example_main.go b/client_example_main.go index 4cda6ac..4e7e1ea 100644 --- a/client_example_main.go +++ b/client_example_main.go @@ -7,44 +7,18 @@ import ( c "github.com/trendrr/goshire/client" // "os" // "runtime/pprof" - // _ "net/http/pprof" - // "net/http" + _ "net/http/pprof" + "net/http" "runtime" ) +func asyncTest(client c.Client, total int) { -func main() { - runtime.GOMAXPROCS(runtime.NumCPU()) -//assumes a running server on port 8009 - log.Println("HERE") - // client := NewHttp("localhost:8010") - client := c.NewJson("localhost", 8009) - // with Poolsize = 10 and maxInflight = 500 - // 2013/05/16 12:56:28 Pinged 100000 in 38 seconds - - client.PoolSize = 10 - client.MaxInFlight = 500 - err := client.Connect() - if err != nil { - log.Println(err) - } - defer client.Close() - //warm it up - res, err := client.ApiCallSync(cheshire.NewRequest("/ping", "GET"), 10*time.Second) - if err != nil { - log.Printf("error %s") - } - log.Println(res) - - - // start the http server for profiling - // go func() { - // log.Println(http.ListenAndServe("localhost:6060", nil)) - // }() + resChan := make(chan *cheshire.Response, 20) errorChan := make(chan error, 200) - total := 1000000 + start := time.Now().Unix() sent := total @@ -59,6 +33,9 @@ func main() { log.Printf("apicall error %s", err) sent-- } + // if i % 2 == 0 { + // time.Sleep(1 * time.Millisecond) + // } } }() count := 0 @@ -73,7 +50,7 @@ func main() { log.Printf("RESULT %s", res) } - case <-errorChan: + case err :=<-errorChan: count++ log.Printf("ERROR FROM CHAN %s", err) } @@ -85,4 +62,60 @@ func main() { } log.Printf("Pinged %d in %d", total, (time.Now().Unix() - start)) + +} + +func syncTest(client c.Client, total int) { + + start := time.Now().Unix() + + + + for i :=0; i < total; i++ { + if i % 1000 == 0 { + log.Printf("Sending %d", i) + } + _, err := client.ApiCallSync(cheshire.NewRequest("/ping", "GET"), 2 * time.Second) + if err != nil { + log.Printf("apicall error %s", err) + } + } + + log.Printf("Pinged %d in %d", total, (time.Now().Unix() - start)) + +} + +func main() { + runtime.GOMAXPROCS(runtime.NumCPU()) +//assumes a running server on port 8009 + log.Println("HERE") + + // start the http server for profiling + go func() { + log.Println(http.ListenAndServe("localhost:6060", nil)) + }() + + // client := NewHttp("localhost:8010") + client := c.NewBin("localhost", 8011) + // client := c.NewJson("localhost", 8009) + + // with Poolsize = 10 and maxInflight = 500 + // 2013/05/16 12:56:28 Pinged 100000 in 38 seconds + + client.PoolSize = 10 + client.MaxInFlight = 500 + err := client.Connect() + if err != nil { + log.Println(err) + } + defer client.Close() + //warm it up + res, err := client.ApiCallSync(cheshire.NewRequest("/ping", "GET"), 10*time.Second) + if err != nil { + log.Printf("error %s") + } + log.Println(res) + + asyncTest(client, 1000000) + } \ No newline at end of file diff --git a/example_config.yaml b/example_config.yaml index ab3df64..180475c 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -13,4 +13,5 @@ http: json: port: 8009 - +bin: + port: 8011 diff --git a/example_main.go b/example_main.go index 8f22a98..5970be7 100644 --- a/example_main.go +++ b/example_main.go @@ -4,21 +4,23 @@ import ( "log" "github.com/trendrr/goshire/cheshire" "github.com/trendrr/goshire/cheshire/impl/gocache" - + "runtime" ) type DummyFilter struct { filterName string } func (this *DummyFilter) Before(*cheshire.Txn) bool { - log.Printf("BEFORE! (%s) \n", this.filterName) + // log.Printf("BEFORE! (%s) \n", this.filterName) return true } func (this *DummyFilter) After(*cheshire.Response, *cheshire.Txn) { - log.Printf("AFTER! (%s) \n", this.filterName) + // log.Printf("AFTER! (%s) \n", this.filterName) } func main() { + runtime.GOMAXPROCS(runtime.NumCPU()) + log.Println(cheshire.RandString(32)) //this one will get executed on every request.