Skip to content

Instantly share code, notes, and snippets.

@enriclluelles
Created April 20, 2014 09:46
Show Gist options
  • Save enriclluelles/11109933 to your computer and use it in GitHub Desktop.
Save enriclluelles/11109933 to your computer and use it in GitHub Desktop.
Consume 2.4gb of RAM firing blocked goroutines
package main
import (
"fmt"
"time"
)
var counter int = 0
var goroutines int = 500000
var c chan interface{}
func main() {
fmt.Println("starting")
c = make(chan interface{})
go reporter()
starter()
for i := goroutines; i > 0; i-- {
<- c
counter--
if i % 1000 == 0 {
time.Sleep(1 * time.Nanosecond)
}
}
close(c)
for {
time.Sleep(1 * time.Second)
}
}
func starter() {
for i := goroutines; i > 0; i-- {
if i % 1000 == 0 {
time.Sleep(1 * time.Nanosecond)
}
counter++
go func() {
c <- true
}()
}
}
func reporter() {
for {
time.Sleep(500 * time.Millisecond)
fmt.Println("counter:", counter)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment