-
-
Save jcorbin/47ba0b94e37ceb1ae8aa751e931dbb24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net" | |
"time" | |
) | |
func main() { | |
n := 0 | |
t := time.NewTicker(time.Second) | |
c, err := net.Dial("tcp", "localhost:8888") | |
if err != nil { | |
log.Fatal(err) | |
} | |
for { | |
select { | |
case <-t.C: | |
fmt.Println(n, "req/sec") | |
n = 0 | |
default: | |
fmt.Fprintln(c, "10") | |
n = n + 1 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"net" | |
"strconv" | |
) | |
func main() { | |
ln, err := net.Listen("tcp", ":8888") | |
if err != nil { | |
log.Fatal(err) | |
} | |
for { | |
c, err := ln.Accept() | |
if err == nil { | |
go serve(c) | |
} | |
} | |
} | |
func fib(n int) int { | |
if n <= 2 { | |
return 1 | |
} else { | |
return fib(n-1) + fib(n-2) | |
} | |
} | |
func serve(c net.Conn) { | |
bs := bufio.NewScanner(c) | |
for bs.Scan() { | |
n, _ := strconv.Atoi(bs.Text()) | |
go func() { | |
res := fib(n) | |
fmt.Fprintf(c, "%d: %s\n", n, strconv.Itoa(res)) | |
}() | |
} | |
if bs.Err() != nil { | |
log.Println("error") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
panic: net: inconsistent fdMutex | |
goroutine 1145194 [running]: | |
panic(0x126cc0, 0xc94cf02860) | |
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6 | |
net.(*fdMutex).RWLock(0xc8200620e0, 0x0, 0xc94d37f61e) | |
/usr/local/Cellar/go/1.6/libexec/src/net/fd_mutex.go:136 +0x20c | |
net.(*netFD).writeLock(0xc8200620e0, 0x0, 0x0) | |
/usr/local/Cellar/go/1.6/libexec/src/net/fd_unix.go:194 +0x39 | |
net.(*netFD).Write(0xc8200620e0, 0xc94cf02848, 0x7, 0x8, 0x0, 0x0, 0x0) | |
/usr/local/Cellar/go/1.6/libexec/src/net/fd_unix.go:319 +0x6c | |
net.(*conn).Write(0xc820088020, 0xc94cf02848, 0x7, 0x8, 0x0, 0x0, 0x0) | |
/usr/local/Cellar/go/1.6/libexec/src/net/net.go:184 +0xe4 | |
fmt.Fprintf(0x440028, 0xc820088020, 0x18bf18, 0x7, 0xc94d9e0f70, 0x2, 0x2, 0x0, 0x0, 0x0) | |
/usr/local/Cellar/go/1.6/libexec/src/fmt/print.go:189 +0xb2 | |
main.serve.func1(0xa, 0x489440, 0xc820088020) | |
/Users/twexler/dev/tmp/fib.go:38 +0x1d1 | |
created by main.serve | |
/Users/twexler/dev/tmp/fib.go:39 +0x18d | |
exit status 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment