Skip to content

Commit

Permalink
Revert "(DAL) Pooling broadcast (#2246)"
Browse files Browse the repository at this point in the history
This reverts commit 12378ae.
  • Loading branch information
nick-bisonai committed Aug 28, 2024
1 parent 111f832 commit 546772e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions node/pkg/dal/hub/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"bisonai.com/miko/node/pkg/dal/collector"
dalcommon "bisonai.com/miko/node/pkg/dal/common"
"bisonai.com/miko/node/pkg/dal/utils/stats"
"bisonai.com/miko/node/pkg/utils/pool"
"github.com/rs/zerolog/log"
"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
Expand All @@ -30,12 +29,10 @@ type Hub struct {
Unregister chan *websocket.Conn
broadcast map[string]chan *dalcommon.OutgoingSubmissionData
mu sync.RWMutex
pool *pool.Pool
}

const (
MAX_CONNECTIONS = 10
WORKER_COUNT = 100
CleanupInterval = time.Hour
)

Expand All @@ -56,13 +53,10 @@ func NewHub(configs map[string]Config) *Hub {
Register: make(chan *websocket.Conn),
Unregister: make(chan *websocket.Conn),
broadcast: make(map[string]chan *dalcommon.OutgoingSubmissionData),
pool: pool.NewPool(WORKER_COUNT),
}
}

func (h *Hub) Start(ctx context.Context, collector *collector.Collector) {
h.pool.Run(ctx)

go h.handleClientRegistration()

h.initializeBroadcastChannels(collector)
Expand Down Expand Up @@ -157,19 +151,24 @@ func (h *Hub) broadcastDataForSymbol(ctx context.Context, symbol string) {
}

func (h *Hub) castSubmissionData(ctx context.Context, data *dalcommon.OutgoingSubmissionData, symbol *string) {
var wg sync.WaitGroup

h.mu.RLock()
defer h.mu.RUnlock()

for client, subscriptions := range h.Clients {
if _, ok := subscriptions[*symbol]; ok {
h.pool.AddJob(func() {
err := wsjson.Write(ctx, client, data)
wg.Add(1)
go func(entry *websocket.Conn) {
defer wg.Done()
err := wsjson.Write(ctx, entry, data)
if err != nil {
log.Warn().Err(err).Msg("failed to write message to client")
}
})
}(client)
}
}
wg.Wait()
}

func (h *Hub) cleanupJob(ctx context.Context) {
Expand Down
4 changes: 2 additions & 2 deletions node/pkg/utils/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func (p *Pool) Run(ctx context.Context) {
p.IsRunning = true

for i := 0; i < p.workerCount; i++ {
go p.runWorker(poolCtx)
go p.worker(poolCtx)
}
}

func (p *Pool) runWorker(ctx context.Context) {
func (p *Pool) worker(ctx context.Context) {
for {
select {
case job := <-p.jobChannel:
Expand Down

0 comments on commit 546772e

Please sign in to comment.