Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Jul 9, 2014
1 parent bb5391d commit 9681334
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gb.go
Expand Up @@ -47,7 +47,7 @@ func main() {
}

func supervise(supervised Supervised, maxTime *int64) {
time.Sleep(*maxTime * 1000000)
time.Sleep(time.Duration(*maxTime) * time.Millisecond)
log.Print("WARN! gb stopped due to timeout. Work lost.")
supervised.Shutdown()
os.Exit(1)
Expand Down
11 changes: 5 additions & 6 deletions http.go
Expand Up @@ -2,10 +2,9 @@ package main

import (
"encoding/base64"
"http"
"net/http"
"log"
"os"
"url"
"net/url"
)

const (
Expand Down Expand Up @@ -73,7 +72,7 @@ func (e Error) String() string {
return string(e)
}

func (self *HTTPClient) defaultRequest() (req *http.Request, err os.Error) {
func (self *HTTPClient) defaultRequest() (req *http.Request, err error) {
var h http.Header = map[string][]string{}
req = new(http.Request)
req.Method = self.method
Expand Down Expand Up @@ -105,7 +104,7 @@ var gbTransport *http.Transport = &http.Transport{DisableKeepAlives: true}
//Perform the HTTP method against the target host.
//Auth is handled if Auth was previously invoked to set
//user info.
func (c *HTTPClient) DoRequest() (response *http.Response, err os.Error) {
func (c *HTTPClient) DoRequest() (response *http.Response, err error) {
//Recover if things goes really bad
defer func() {
if e := recover(); e != nil {
Expand All @@ -120,7 +119,7 @@ func (c *HTTPClient) DoRequest() (response *http.Response, err os.Error) {
response, err = gbTransport.RoundTrip(req)

if err != nil {
log.Printf("Error performing Request: %v", err.String())
log.Printf("Error performing Request: %v", err)
return nil, err
}
if response.StatusCode == http.StatusUnauthorized && c.basicAuth {
Expand Down
16 changes: 9 additions & 7 deletions master.go
Expand Up @@ -11,10 +11,11 @@ package main
import (
"flag"
"log"
"netchan"
"old/template"
"text/template"
"strings"
"time"

"code.google.com/p/go.exp/old/netchan"
)

var (
Expand Down Expand Up @@ -119,7 +120,8 @@ type Summary struct {
}

func (self *Summary) String() string {
t := template.MustParse(OutPutTemplate, CustomFormatter)
t := template.Must(template.New("gb").Parse(OutPutTemplate))
t.Funcs(CustomFormatter)
sw := new(StringWritter)
t.Execute(sw, self)
return sw.s
Expand All @@ -135,13 +137,13 @@ func (self *Master) Shutdown() {
self.exptr.Hangup("masterChannel")
}
if self.summary.End == 0 {
self.summary.End = time.Nanoseconds()
self.summary.End = time.Now().UnixNano()
self.summary.Elapsed = self.summary.End - self.summary.Start
}
}

func newSession(timeout int64) Session {
s := &Session{Id: time.Nanoseconds(), Timeout: timeout}
s := &Session{Id: time.Now().UnixNano(), Timeout: timeout}
return *s
}

Expand Down Expand Up @@ -214,7 +216,7 @@ func (m *Master) BenchMark(ctrlChan chan bool) {
//whole request.
func (self *Master) summarize() {
log.Print("Tasks distributed. Waiting for summaries...")
self.summary.Start = time.Nanoseconds()
self.summary.Start = time.Now().UnixNano()
workers := self.runningTasks
var avgs float64
for tSummary := range self.channel {
Expand All @@ -233,7 +235,7 @@ func (self *Master) summarize() {
if self.summary.Min == -1 {
self.summary.Min = 0
}
self.summary.End = time.Nanoseconds()
self.summary.End = time.Now().UnixNano()
self.summary.Elapsed = (self.summary.End - self.summary.Start)
self.summary.Avg = float64(avgs / float64(workers))
self.summary.RequestsPerSecond = int64(self.summary.TotalSuc*1000) / (self.summary.Elapsed / 1000000)
Expand Down
26 changes: 12 additions & 14 deletions util.go
Expand Up @@ -9,11 +9,9 @@
package main

import (
"errors"
"fmt"
"io"
"old/template"
"os"
"strconv"
"text/template"
"strings"
"time"
)
Expand Down Expand Up @@ -59,31 +57,31 @@ type StringWritter struct {
}

//Writes the template as string
func (self *StringWritter) Write(p []byte) (n int, err os.Error) {
func (self *StringWritter) Write(p []byte) (n int, err error) {
self.s += string(p)
return len(self.s), nil
}

//Parse any flag represented by
//a key-value with a separator
func parseKV(param *string, separator, errmsg string) (k, v string, err os.Error) {
func parseKV(param *string, separator, errmsg string) (k, v string, err error) {
if *param == "" {
return
}
data := strings.SplitN(*param, separator, 2)

if len(data) != 2 {
err = os.NewError(errmsg)
err = errors.New(errmsg)
}
k = data[0]
v = data[1]
return
}

func counting(f func()) int64 {
start := time.Nanoseconds()
start := time.Now().UnixNano()
f()
return time.Nanoseconds() - start
return time.Now().UnixNano() - start
}

//Just converts a nanosecond value to a milisecond value.
Expand All @@ -95,12 +93,12 @@ func nan2mi(value float64) float64 {
//f2mi means float64 to miliseconds and i2mi
//means int64 to miliseconds, returning a float64
//representing it
var CustomFormatter = template.FormatterMap{
"f2mi": func(w io.Writer, format string, value ...interface{}) {
fmt.Fprint(w, strconv.Ftoa64(nan2mi(value[0].(float64)), 'f', -1))
var CustomFormatter = template.FuncMap{
"f2mi": func(value ...interface{}) string {
return fmt.Sprint(nan2mi(value[0].(float64)), 'f', -1)
},
"i2mi": func(w io.Writer, format string, value ...interface{}) {
fmt.Fprintf(w, strconv.Ftoa64(nan2mi(float64(value[0].(int64))), 'f', -1))
"i2mi": func(value ...interface{}) string {
return fmt.Sprint(nan2mi(float64(value[0].(int64))), 'f', -1)
},
}

Expand Down
18 changes: 9 additions & 9 deletions workers.go
Expand Up @@ -9,12 +9,12 @@
package main

import (
"http"
"net/http"
"log"
"netchan"
"os"
"sync"
"time"

"code.google.com/p/go.exp/old/netchan"
)

//Represents a set of request to be performed
Expand Down Expand Up @@ -99,7 +99,7 @@ var _sessions map[int64]chan WorkSummary = make(map[int64]chan WorkSummary)
var mu *sync.RWMutex = new(sync.RWMutex)

//Helper function to import the Master channel from masterAddr
func importMasterChan(t Task) (c chan WorkSummary, err os.Error) {
func importMasterChan(t Task) (c chan WorkSummary, err error) {
mu.Lock()
defer mu.Unlock()
if c, present := _sessions[t.Session.Id]; present {
Expand Down Expand Up @@ -128,10 +128,10 @@ func importMasterChan(t Task) (c chan WorkSummary, err os.Error) {
//A cache watcher function cleans up the cache after
//2 times the session length
func cacheWatcher(session Session) {
time.Sleep(session.Timeout * 2)
time.Sleep(time.Duration(session.Timeout * 2))
mu.Lock()
log.Printf("Cleanning up Session %v", session.Id)
_sessions[session.Id] = _sessions[session.Id], false
delete(_sessions, session.Id)
mu.Unlock()
}

Expand Down Expand Up @@ -175,10 +175,10 @@ func (w *LocalWorker) execute(task Task) {
var min int64 = -1
//perform n times the request
for i := 0; i < task.Requests; i++ {
start := time.Nanoseconds()
start := time.Now().UnixNano()
resp, err := client.DoRequest()

elapsed := time.Nanoseconds() - start
elapsed := time.Now().UnixNano() - start
if err == nil && resp != nil && resp.StatusCode == http.StatusOK {
totalSuc += 1
totalElapsed += elapsed
Expand Down Expand Up @@ -214,7 +214,7 @@ type ProxyWorker struct {

//Creates a new Proxy importing 'workerChannel' from Worker running
//on workerAddr
func NewProxyWorker(workerAddr string) (p *ProxyWorker, err os.Error) {
func NewProxyWorker(workerAddr string) (p *ProxyWorker, err error) {
log.Printf("Setting up a ProxyWorker for %s", workerAddr)
p = new(ProxyWorker)

Expand Down

0 comments on commit 9681334

Please sign in to comment.