Skip to content

Commit

Permalink
update examples to use binary protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
dustismo committed Jul 2, 2013
1 parent 46b0795 commit 7940007
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 36 deletions.
97 changes: 65 additions & 32 deletions client_example_main.go
Expand Up @@ -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
Expand All @@ -59,6 +33,9 @@ func main() {
log.Printf("apicall error %s", err)
sent--
}
// if i % 2 == 0 {
// time.Sleep(1 * time.Millisecond)
// }
}
}()
count := 0
Expand All @@ -73,7 +50,7 @@ func main() {
log.Printf("RESULT %s", res)
}

case <-errorChan:
case err :=<-errorChan:
count++
log.Printf("ERROR FROM CHAN %s", err)
}
Expand All @@ -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)

}
3 changes: 2 additions & 1 deletion example_config.yaml
Expand Up @@ -13,4 +13,5 @@ http:
json:
port: 8009


bin:
port: 8011
8 changes: 5 additions & 3 deletions example_main.go
Expand Up @@ -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.
Expand Down

0 comments on commit 7940007

Please sign in to comment.