Skip to content

Fast Multisocket/Multichannel Redis PubSub Websocket Adapter#1375

Open
jonsilverman50-star wants to merge 53 commits intoamberframework:masterfrom
jonsilverman50-star:master
Open

Fast Multisocket/Multichannel Redis PubSub Websocket Adapter#1375
jonsilverman50-star wants to merge 53 commits intoamberframework:masterfrom
jonsilverman50-star:master

Conversation

@jonsilverman50-star
Copy link

@jonsilverman50-star jonsilverman50-star commented Feb 21, 2026

Description of the Change

This is a better Redis adapter for Amber Websockets. It supposed unlimited sockets and channels and uses the Redis PubSub backend properly. In the current Redis adapter you can only subscribe to one channel. This needs merge. Also included are updates for cleaning up dead sockets and rescuing sends on dead sockets. That was needed for stability.

Please see my site https://gbalda.org for an example in production.

Alternate Designs

None.

Benefits

Speed increases for sites that use multiple sockets.

Possible Drawbacks

Only works with a process count of 1. (production.yml process_count)
Tests that I wrote long ago need fix. I'll try to fix them.

mixflame and others added 30 commits June 15, 2021 19:33
redis fix 3?

redis fix 4?

try this

try this next

try hacking redis adapter again

try hacking redis adapter again

will this fix it?

better amber redis websocket patch

remove extraneous puts

change incorrect comment, explain how patch works in comment

fiber.yields for better execution

subscribe once and on the fly

oopsies signed jsilver

avoid namespace concerns

weird code but will this work

please sir, infer my type

keep subscribe channel open forever

take out fiber yields and subscribe in on message... will be in loop i think

trying this

oopsie 2

test

choose function to activate better

if i understand crystal-redis right this should work

fix

try this

try this

try this

happy wise thinking programmer zen choice: register callback FIRST then subscribe

will this wakeup websocket beat thread

try something

better

tests for redis adapter

might need this

might need this 2

show heartbeat

remove dead sockets

fix

lengthen deadbeat socket interval

debug

use Fiber.yield

bug fix hang fix

recover if the subscriber breaks

dont loop in loop

a good patch wit some consideration... dont get stuck anywhere

better?

remove race condition

reset to 2am last night

this might have been the only issue

keep forgetting to do this

autoselect adapter, subscribe early

this is beginning to become hard

please help i am trapped inside a computer program

setup adapter early

initialize and subscribe early

dont load pubsub adapter yet

cleanup

get tests passing... ready to merge

make tests fast

attempt subscribe when registering message handlers

remake subscription block fiber if subscribing no longer works without block

make logs faster, remove unneeded puts, use logging mechanism for faster logging

add logging to find out why sockets are left closed and undeleted

nicer client socket

we probably do need to yield in these websocket loops so pings can occur

remove spam logging i added

sleep the beat interval when waiting for pongs, this allows fibers to catch up and all pongs to get received, correct me if i'm wrong

apparently, HTTP::WebSocket itself from Crystal core lib is doing a loop do... for its block/event loop and since im now using fibers we have to yield for the pings to come and go properly... also testing this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants