MOAR SPEED

this needs some severe cleaning
master
Jordan Orelli 11 years ago
parent fc5db3defb
commit af39963304

@ -80,15 +80,20 @@ func main() {
sent := make(chan value, options.buffer)
go streamValues(infile, c)
go func() {
w := bufio.NewWriterSize(conn, 4048)
w := bufio.NewWriterSize(conn, 16384)
defer func() {
close(sent)
fmt.Println("All data transferred. Waiting for the last reply...")
}()
count := 0
for r := range c {
count++
if r.ok() {
r.val().Write(w)
if count == 100 {
w.Flush()
count = 0
}
sent <- r.val()
} else {
fmt.Fprintf(os.Stderr, "InputError: %v\n", r.err())

@ -125,7 +125,11 @@ func readString(b []byte) (value, error) {
}
func (s String) Write(w io.Writer) (int, error) {
return fmt.Fprintf(w, "+%s\r\n", s)
w.Write([]byte{'+'})
w.Write([]byte(s))
w.Write([]byte{'\r', '\n'})
return 0, nil
// return fmt.Fprintf(w, "+%s\r\n", s)
}
// ------------------------------------------------------------------------------
@ -137,7 +141,11 @@ func readError(b []byte) (value, error) {
}
func (e Error) Write(w io.Writer) (int, error) {
return fmt.Fprintf(w, "-%s\r\n")
w.Write([]byte{'-'})
w.Write([]byte(e))
w.Write([]byte{'\r', '\n'})
return 0, nil
// return fmt.Fprintf(w, "-%s\r\n")
}
// ------------------------------------------------------------------------------
@ -153,7 +161,11 @@ func readInteger(b []byte) (value, error) {
}
func (i Integer) Write(w io.Writer) (int, error) {
return fmt.Fprintf(w, ":%d\r\n", i)
w.Write([]byte{':'})
w.Write([]byte(strconv.Itoa(int(i))))
w.Write([]byte{'\r', '\n'})
return 0, nil
// return fmt.Fprintf(w, ":%d\r\n", i)
}
// ------------------------------------------------------------------------------
@ -198,7 +210,13 @@ func readBulkString(prefix []byte, r io.Reader) (value, error) {
}
func (s BulkString) Write(w io.Writer) (int, error) {
return fmt.Fprintf(w, "$%d\r\n%s\r\n", len(s), s)
w.Write([]byte{'$'})
w.Write([]byte(strconv.Itoa(len(s))))
w.Write([]byte{'\r', '\n'})
w.Write([]byte(s))
w.Write([]byte{'\r', '\n'})
return 0, nil
// return fmt.Fprintf(w, "$%d\r\n%s\r\n", len(s), s)
}
// -----------------------------------------------------------------------------------------
@ -230,21 +248,26 @@ func readArray(prefix []byte, r *bufio.Reader) (value, error) {
}
func (a Array) Write(w io.Writer) (int, error) {
n, err := fmt.Fprintf(w, "*%d\r\n", len(a))
if err != nil {
return n, err
}
var (
nn int
e error
)
w.Write([]byte{'*'})
w.Write([]byte(strconv.Itoa(len(a))))
w.Write([]byte{'\r', '\n'})
// n, err := fmt.Fprintf(w, "*%d\r\n", len(a))
// if err != nil {
// return n, err
// }
// var (
// nn int
// e error
// )
for i := 0; i < len(a); i++ {
nn, e = a[i].Write(w)
n += nn
if e != nil {
return n, e
}
a[i].Write(w)
// nn, e = a[i].Write(w)
// n += nn
// if e != nil {
// return n, e
// }
}
return n, nil
// return n, nil
return 0, nil
}

Loading…
Cancel
Save