Skip to content

Instantly share code, notes, and snippets.

@derekcollison
Created December 19, 2015 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derekcollison/be9419e413adb83ff87d to your computer and use it in GitHub Desktop.
Save derekcollison/be9419e413adb83ff87d to your computer and use it in GitHub Desktop.
Max Subscriptions in Gp
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