add chunk-info option

master
Jordan Orelli 11 years ago
parent 8a963f5f6a
commit aa088a3fd2

@ -15,13 +15,14 @@ var chunk_target = 250 * time.Millisecond
var chunk_max = 10000 var chunk_max = 10000
var options struct { var options struct {
host string host string
port int port int
password string password string
buffer int buffer int
pipe bool pipe bool
profile string profile string
verbose bool verbose bool
chunkInfo bool
} }
func usage(status int) { func usage(status int) {
@ -35,7 +36,7 @@ type chunk struct {
t time.Time t time.Time
} }
func (c *chunk) send(w *bufio.Writer, responses chan maybe) { func (c *chunk) send(w *bufio.Writer, responses chan maybe) (int, int) {
start := time.Now() start := time.Now()
for _, v := range c.vals { for _, v := range c.vals {
v.Write(w) v.Write(w)
@ -47,7 +48,7 @@ func (c *chunk) send(w *bufio.Writer, responses chan maybe) {
response, ok := <-responses response, ok := <-responses
if !ok { if !ok {
fmt.Fprintf(os.Stderr, "ohhhhhhhhhhhhh fuck\n") fmt.Fprintf(os.Stderr, "ohhhhhhhhhhhhh fuck\n")
return return -1, -1
} }
if response.ok() { if response.ok() {
switch r := response.val().(type) { switch r := response.val().(type) {
@ -73,7 +74,7 @@ func (c *chunk) send(w *bufio.Writer, responses chan maybe) {
time.Sleep(sleep) time.Sleep(sleep)
avg := time.Duration(int64(elapsed) / int64(len(c.vals))) avg := time.Duration(int64(elapsed) / int64(len(c.vals)))
next_size := int(int64(chunk_target) / int64(avg)) next_size := int(int64(chunk_target) / int64(avg))
if true { if options.chunkInfo {
fmt.Printf("id: %d errors: %d replies: %d total: %d sent: %d elapsed: %v avg: %v size: %v sleep: %v next_size: %v\n", fmt.Printf("id: %d errors: %d replies: %d total: %d sent: %d elapsed: %v avg: %v size: %v sleep: %v next_size: %v\n",
c.id, errors, replies, errors+replies, len(c.vals), elapsed, avg, size, sleep, next_size) c.id, errors, replies, errors+replies, len(c.vals), elapsed, avg, size, sleep, next_size)
} }
@ -85,6 +86,7 @@ func (c *chunk) send(w *bufio.Writer, responses chan maybe) {
if chunk_size > chunk_max { if chunk_size > chunk_max {
chunk_size = chunk_max chunk_size = chunk_max
} }
return errors, replies
} }
func main() { func main() {
@ -150,6 +152,7 @@ func main() {
id := 1 id := 1
requests := &chunk{id: id, vals: make([]value, 0, chunk_size)} requests := &chunk{id: id, vals: make([]value, 0, chunk_size)}
errors, replies := 0, 0
for m := range c { for m := range c {
if !m.ok() { if !m.ok() {
fmt.Fprintf(os.Stderr, "InputError: %v\n", m.err()) fmt.Fprintf(os.Stderr, "InputError: %v\n", m.err())
@ -157,17 +160,21 @@ func main() {
} }
requests.vals = append(requests.vals, m.val()) requests.vals = append(requests.vals, m.val())
if len(requests.vals) == cap(requests.vals) { if len(requests.vals) == cap(requests.vals) {
requests.send(w, responses) nErrors, nReplies := requests.send(w, responses)
errors += nErrors
replies += nReplies
id++ id++
requests = &chunk{id: id, vals: make([]value, 0, chunk_size)} requests = &chunk{id: id, vals: make([]value, 0, chunk_size)}
} }
} }
if len(requests.vals) > 0 { if len(requests.vals) > 0 {
requests.send(w, responses) nErrors, nReplies := requests.send(w, responses)
errors += nErrors
replies += nReplies
} }
// fmt.Println("Last reply received from server.") fmt.Println("Last reply received from server.")
// fmt.Printf("errors: %d, replies: %d\n", errors, replies) fmt.Printf("errors: %d, replies: %d\n", errors, replies)
} }
func init() { func init() {
@ -178,6 +185,7 @@ func init() {
flag.BoolVar(&options.pipe, "pipe", false, "transfers input from stdin to server") flag.BoolVar(&options.pipe, "pipe", false, "transfers input from stdin to server")
flag.StringVar(&options.profile, "profile", "", "pprof file output for performance debugging") flag.StringVar(&options.profile, "profile", "", "pprof file output for performance debugging")
flag.BoolVar(&options.verbose, "v", false, "verbose mode (prints all requests and responses)") flag.BoolVar(&options.verbose, "v", false, "verbose mode (prints all requests and responses)")
flag.BoolVar(&options.chunkInfo, "chunk-info", false, "show chunk info")
} }
/* /*

Loading…
Cancel
Save