Created
April 20, 2014 09:46
-
-
Save enriclluelles/11109933 to your computer and use it in GitHub Desktop.
Consume 2.4gb of RAM firing blocked goroutines
This file contains hidden or 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" | |
"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