Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] First basic draft of the dispatch system using Redis #1310

Merged
merged 7 commits into from
Sep 8, 2023

Conversation

lasryaric
Copy link
Contributor

@lasryaric lasryaric commented Sep 7, 2023

This is a first draft of what the dispatch system could look like, using Redis streams.

The two main Redis commands used are:

  • XADD to add data to a "persistent stream".
  • XREAD to read data from the persistant stream.

Let me know what you think.

@lasryaric lasryaric marked this pull request as draft September 7, 2023 15:19
docker-compose.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@spolu spolu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAICE

@spolu
Copy link
Contributor

spolu commented Sep 7, 2023

Reminder that this is on the blocking path for moving to the UI but it looks simple and well advanced enough that we likely will have it ready by tomorrow \o/

@lasryaric
Copy link
Contributor Author

lasryaric commented Sep 7, 2023 via email

@lasryaric
Copy link
Contributor Author

lasryaric commented Sep 7, 2023 via email

@spolu
Copy link
Contributor

spolu commented Sep 7, 2023

re qdrant, do we need it?

@lasryaric
Copy link
Contributor Author

Re qdrant port: I use it often for debugging vis curl.

@spolu
Copy link
Contributor

spolu commented Sep 8, 2023

Gotcha I realize now this is not impacting production 👍

@lasryaric
Copy link
Contributor Author

👍 side note but Qdrant cloud exposes this port, and I also use it there for debugging / profiling sometimes.

Copy link
Contributor

@spolu spolu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If conversation sub (which I presume you created for minimal testing) then LGTM

},
});
res.status(200).end();
await p;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the await? why not void?

Copy link
Contributor

@spolu spolu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually a few comments

front/lib/redis.ts Show resolved Hide resolved
front/lib/api/assistant/pubsub.ts Outdated Show resolved Hide resolved
front/lib/api/assistant/pubsub.ts Outdated Show resolved Hide resolved
front/lib/api/assistant/pubsub.ts Outdated Show resolved Hide resolved
front/lib/api/assistant/pubsub.ts Outdated Show resolved Hide resolved
while (true) {
const events = await client.xRead(
{ key: pubsubChannel, id: lastEventId ? lastEventId : "0-0" },
{ COUNT: 1, BLOCK: 10000 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan with 10s here? what happens once it's reached?

front/lib/api/assistant/pubsub.ts Outdated Show resolved Hide resolved
@lasryaric
Copy link
Contributor Author

lasryaric commented Sep 8, 2023 via email

@lasryaric lasryaric force-pushed the aric-aissistant_dispatch branch from a6834c4 to 09d1bd3 Compare September 8, 2023 11:52
@lasryaric lasryaric requested a review from spolu September 8, 2023 12:19
@lasryaric lasryaric marked this pull request as ready for review September 8, 2023 12:19
@lasryaric
Copy link
Contributor Author

Ready for review on my side.

const events = await client.xRead(
{ key: pubsubChannel, id: lastEventId ? lastEventId : "0-0" },
// weird, xread does not return on new message when count is = 1. Anything over 1 works.
{ COUNT: 10, BLOCK: 60 * 1000 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// weird right in the middle of the dispatch system is not great.

COUNT must have an impact no? Does it work if we have more than 10 events in the queue?

});
}

const conv = await Conversation.findOne({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the Conversation loading for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we call getConversationEvents on a bogus sId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will block until the timeout has been reached out and return 0 event.

while (true) {
const events = await redis.xRead(
{ key: pubsubChannel, id: lastEventId ? lastEventId : "0-0" },
// weird, xread does not return on new message when count is = 1. Anything over 1 works.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Reading the code to prepare, thanks for all that aric 🙏

NRE - Just asking : something I don't understand here: if we use count = 1 then only 1 event on the array max right, and no need for the loop below? Why not get e.g. count = 100, to limit the calls to redis -- and keep the loop?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to drop in uninvited 😅 hope I'm not disturbing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context: this comment was wrong, count is honored, I am not sure exactly if redis can return more than 1 event when using the blocking call because I have read that it returns on the first one, but for the first call with no "lastEventId" set, it does return multiple rows.

In any case, that's the redis interface, they always return an array, so we'll always have to loop. We could fetch event[0] but it does not change the code much I think. Does it?

@lasryaric lasryaric merged commit cc00fae into main Sep 8, 2023
@lasryaric lasryaric deleted the aric-aissistant_dispatch branch September 8, 2023 14:37
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