moving everything to github
This commit is contained in:
60
README.md
60
README.md
@@ -6,7 +6,7 @@ I started to develop what is now GubGub in one of my personal projects but I soo
|
|||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go get -u gitlab.com/naterciom/gubgub
|
go get github.com/naterciom/gubgub@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
@@ -17,32 +17,32 @@ We'll be ignoring errors for code brevity!
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitlab.com/naterciom/gubgub"
|
"github.com/naterciom/gubgub"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MyMessage struct {
|
type MyMessage struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func consumer(msg MyMessage) {
|
func consumer(msg MyMessage) {
|
||||||
fmt.Printf("Hello %s", msg.Name)
|
fmt.Printf("Hello %s", msg.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
topic := gubgub.NewAsyncTopic[MyMessage]()
|
topic := gubgub.NewAsyncTopic[MyMessage]()
|
||||||
defer topic.Close() // Returns after all messages are delivered
|
defer topic.Close() // Returns after all messages are delivered
|
||||||
|
|
||||||
_ = topic.Subscribe(gubgub.Forever(consumer))
|
_ = topic.Subscribe(gubgub.Forever(consumer))
|
||||||
|
|
||||||
// The AsyncTopic doesn't wait for the subscriber to be registered so, for the purposes of this
|
// The AsyncTopic doesn't wait for the subscriber to be registered so, for the purposes of this
|
||||||
// example, we sleep on it.
|
// example, we sleep on it.
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
|
|
||||||
_ = topic.Publish(MyMessage{Name: "John Smith"}) // Returns immediately
|
_ = topic.Publish(MyMessage{Name: "John Smith"}) // Returns immediately
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -62,10 +62,10 @@ Use the `WithOnClose` option when creating the topic to perform any extra clean
|
|||||||
|
|
||||||
GubGub offers 2 kinds of topics:
|
GubGub offers 2 kinds of topics:
|
||||||
|
|
||||||
* **SyncTopic** - Publishing blocks until the message was delivered to all subscribers.
|
* **SyncTopic** - Publishing blocks until the message was delivered to all subscribers.
|
||||||
Subscribing blocks until the subscriber is registered.
|
Subscribing blocks until the subscriber is registered.
|
||||||
|
|
||||||
* **AsyncTopic** - Publishing schedules the message to be eventually delivered.
|
* **AsyncTopic** - Publishing schedules the message to be eventually delivered.
|
||||||
Subscribing schedules a subscriber to be eventually registered.
|
Subscribing schedules a subscriber to be eventually registered.
|
||||||
Only message delivery is garanteed.
|
Only message delivery is garanteed.
|
||||||
|
|
||||||
@@ -74,25 +74,25 @@ Currently we deliver messages sequenctially (each subscriber gets the message on
|
|||||||
|
|
||||||
## Benchmarks
|
## Benchmarks
|
||||||
|
|
||||||
* **SyncTopic** - Subscribers speed and number **will** have a direct impact the publishing performance.
|
* **SyncTopic** - Subscribers speed and number **will** have a direct impact the publishing performance.
|
||||||
Under the right conditions (few and fast subscribers) this is the most performant topic.
|
Under the right conditions (few and fast subscribers) this is the most performant topic.
|
||||||
|
|
||||||
* **AsyncTopic** - Subscribers speed and number **will not** directly impact the publishing perfomance at the cost of some publishing overhead.
|
* **AsyncTopic** - Subscribers speed and number **will not** directly impact the publishing perfomance at the cost of some publishing overhead.
|
||||||
This is generally the most scalable topic.
|
This is generally the most scalable topic.
|
||||||
|
|
||||||
The following benchmarks are just for topic comparison regarding how the number of subscribers and their speed can impact the publishing performance:
|
The following benchmarks are just for topic comparison regarding how the number of subscribers and their speed can impact the publishing performance:
|
||||||
|
|
||||||
```
|
```
|
||||||
BenchmarkAsyncTopic_Publish/10_NoOp_Subscribers-8 2047338 498.7 ns/op
|
BenchmarkAsyncTopic_Publish/10_NoOp_Subscribers-8 2047338 498.7 ns/op
|
||||||
BenchmarkAsyncTopic_Publish/100_NoOp_Subscribers-8 3317646 535.0 ns/op
|
BenchmarkAsyncTopic_Publish/100_NoOp_Subscribers-8 3317646 535.0 ns/op
|
||||||
BenchmarkAsyncTopic_Publish/1K_NoOp_Subscribers-8 3239110 578.9 ns/op
|
BenchmarkAsyncTopic_Publish/1K_NoOp_Subscribers-8 3239110 578.9 ns/op
|
||||||
BenchmarkAsyncTopic_Publish/10K_NoOp_Subscribers-8 1871702 691.2 ns/op
|
BenchmarkAsyncTopic_Publish/10K_NoOp_Subscribers-8 1871702 691.2 ns/op
|
||||||
BenchmarkAsyncTopic_Publish/10_Slow_Subscribers-8 2615269 433.4 ns/op
|
BenchmarkAsyncTopic_Publish/10_Slow_Subscribers-8 2615269 433.4 ns/op
|
||||||
BenchmarkAsyncTopic_Publish/20_Slow_Subscribers-8 3127874 470.4 ns/op
|
BenchmarkAsyncTopic_Publish/20_Slow_Subscribers-8 3127874 470.4 ns/op
|
||||||
BenchmarkSyncTopic_Publish/10_NoOp_Subscribers-8 24740354 59.69 ns/op
|
BenchmarkSyncTopic_Publish/10_NoOp_Subscribers-8 24740354 59.69 ns/op
|
||||||
BenchmarkSyncTopic_Publish/100_NoOp_Subscribers-8 4135681 488.9 ns/op
|
BenchmarkSyncTopic_Publish/100_NoOp_Subscribers-8 4135681 488.9 ns/op
|
||||||
BenchmarkSyncTopic_Publish/1K_NoOp_Subscribers-8 474122 4320 ns/op
|
BenchmarkSyncTopic_Publish/1K_NoOp_Subscribers-8 474122 4320 ns/op
|
||||||
BenchmarkSyncTopic_Publish/10K_NoOp_Subscribers-8 45790 35583 ns/op
|
BenchmarkSyncTopic_Publish/10K_NoOp_Subscribers-8 45790 35583 ns/op
|
||||||
BenchmarkSyncTopic_Publish/10_Slow_Subscribers-8 357253 3393 ns/op
|
BenchmarkSyncTopic_Publish/10_Slow_Subscribers-8 357253 3393 ns/op
|
||||||
BenchmarkSyncTopic_Publish/20_Slow_Subscribers-8 179725 6688 ns/op
|
BenchmarkSyncTopic_Publish/20_Slow_Subscribers-8 179725 6688 ns/op
|
||||||
```
|
```
|
||||||
|
|||||||
5
async.go
5
async.go
@@ -45,11 +45,12 @@ func NewAsyncTopic[T any](opts ...TopicOption) *AsyncTopic[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close terminates background go routines and prevents further publishing and subscribing. All
|
// Close terminates background go routines and prevents further publishing and subscribing. All
|
||||||
// published messages are garanteed to be delivered once Close returns. This is idempotent.
|
// published messages are garanteed to be delivered once Close returns. This is idempotent and
|
||||||
|
// thread safe.
|
||||||
func (t *AsyncTopic[T]) Close() {
|
func (t *AsyncTopic[T]) Close() {
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
if t.closing {
|
if t.closing {
|
||||||
// Multiple go routines attempted to close this topic. Both should wait for the topic to be
|
// Multiple go routines attempted to close this topic. All should wait for the topic to be
|
||||||
// closed before returning.
|
// closed before returning.
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
<-t.closed
|
<-t.closed
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitlab.com/naterciom/gubgub"
|
"github.com/nmoniz/gubgub"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user