Created
December 19, 2015 12:41
-
-
Save derekcollison/be9419e413adb83ff87d to your computer and use it in GitHub Desktop.
Max Subscriptions in Gp
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 ( | |
"crypto/rand" | |
"encoding/hex" | |
"fmt" | |
"io" | |
"log" | |
"runtime" | |
"github.com/nats-io/nats" | |
) | |
func newSubject() string { | |
u := make([]byte, 13) | |
io.ReadFull(rand.Reader, u) | |
return fmt.Sprintf("DEVICE.%s.OUTPUT", hex.EncodeToString(u)) | |
} | |
func main() { | |
opts := nats.DefaultOptions | |
opts.SubChanLen = 1 | |
opts.Url = "nats://demo.nats.io:4222" | |
nc, err := opts.Connect() | |
if err != nil { | |
log.Fatalf("Can't connect: %v\n", err) | |
} | |
numSubs := 1000000 | |
log.Printf("Starting %d subscriptions\n", numSubs) | |
for i := 0; i < numSubs; i++ { | |
nc.SubscribeSync(newSubject()) | |
} | |
nc.Flush() | |
log.Printf("Done") | |
runtime.Goexit() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment