Skip to content

Instantly share code, notes, and snippets.

💭
Working on NATS.io

Derek Collison derekcollison

💭
Working on NATS.io
Block or report user

Report or block derekcollison

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@derekcollison
derekcollison / Wants N
Created Dec 3, 2018
Subscriber who only wants N responses
View Wants N
// Copyright 2012-2018 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@derekcollison
derekcollison / qsub.go
Created Aug 24, 2018
Simple Queue Subscriber
View qsub.go
// All subscriptions with the same queue name will form a queue
// group at runtime. Each message will be delivered to only one
// subscriber per queue group. You can have as many queue groups
// as you wish, and as many members in a single group as you like.
// Normal subscribers will continue to work as expected.
nc.QueueSubscribe("foo", "job_workers", func(m *Msg) {
// Do some work, then send reply.
nc.Publish(m.ReplyTo, myAnswer)
})
@derekcollison
derekcollison / drain.go
Last active Aug 24, 2018
NATS Drain Mode
View drain.go
package main
import (
"log"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/nats-io/go-nats"
View keybase.md

Keybase proof

I hereby claim:

  • I am derekcollison on github.
  • I am derekcollison (https://keybase.io/derekcollison) on keybase.
  • I have a public key whose fingerprint is 123C 60DB 9DCE 9CB1 B2E8 CA5D 677A 5159 1919 3B29

To claim this, I am signing this object:

View latency.go
package main
import (
"fmt"
"sort"
"sync"
"time"
"github.com/nats-io/go-nats"
)
@derekcollison
derekcollison / max-subs.go
Created Dec 19, 2015
Max Subscriptions in Gp
View max-subs.go
package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
"io"
"log"
"runtime"
@derekcollison
derekcollison / nats_sub_test.js
Last active Dec 18, 2015
Many Subscriptions
View nats_sub_test.js
#!/usr/bin/env node
/* jslint node: true */
'use strict';
var nats = require ('../lib/nats.js').connect('nats://demo.nats.io:4222');
var cuid = require('cuid');
nats.on('error', function(e) {
console.log('Error [' + nats.options.url + ']: ' + e);
@derekcollison
derekcollison / gist:4616831fc476e5f2117e
Created Dec 3, 2015
NATS Performance with 16 publishers
View gist:4616831fc476e5f2117e
~/Development/go/src/github.com/nats-io/nats/examples> ./nats-bench -np 16 -n 100000 foo ok
Starting benchmark
msgs=16X100000, pubs=16, subs=0
#################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
View gist:c0b487861e9a7b07d50a
telnet demo.nats.io 4222
Connected to demo.nats.io.
Escape character is '^]'.
INFO {"server_id":"ad29ea9cbb16f2865c177bbd4db446ca","version":"0.6.8","go":"go1.5.1","host":"0.0.0.0","port":4222,"auth_required":false,"ssl_required":false,"max_payload":1048576}
SUB foo 1
+OK
PUB foo 6
hello!
+OK
MSG foo 1 6
View gist:93d728aee258b34ca94d
~/Development/go/src/github.com/nats-io/gnatsd/test> GOMAXPROCS=3 go test -run="-" -bench="."
PASS
Benchmark___PubNo_Payload-3 10000000 194 ns/op 56.48 MB/s
Benchmark___Pub8b_Payload-3 10000000 186 ns/op 101.77 MB/s
Benchmark__Pub32b_Payload-3 10000000 208 ns/op 210.76 MB/s
Benchmark_Pub256B_Payload-3 5000000 289 ns/op 929.40 MB/s
Benchmark___Pub1K_Payload-3 2000000 630 ns/op 1645.63 MB/s
Benchmark___Pub4K_Payload-3 500000 3255 ns/op 1262.32 MB/s
Benchmark___Pub8K_Payload-3 200000 6903 ns/op 1188.59 MB/s
Benchmark__________PubSub-3 3000000 408 ns/op
You can’t perform that action at this time.