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

William/v2 server #42

Merged
merged 8 commits into from
Sep 8, 2022
Merged

William/v2 server #42

merged 8 commits into from
Sep 8, 2022

Conversation

swansontec
Copy link
Contributor

@swansontec swansontec commented Aug 9, 2022

This replaces #40 and #36. It provides an actual implementation.


@swansontec swansontec force-pushed the william/v2-server branch 2 times, most recently from 94e0037 to 1256164 Compare August 12, 2022 17:23
Copy link
Contributor

@samholmes samholmes left a comment

Choose a reason for hiding this comment

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

Copied the comments for convenience while giving another review.

)
} catch (error) {
if (asMaybeConflictError(error) == null) throw error
await addEvent(connection, event, new Date(created.valueOf() + 1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have been using this strategy in the other servers. It works quite well.

The basic idea is that at least one thread will always be making progress. If thread A, B, and C are all trying to add events at the same time, one will succeed and the other two will fail. That progress means we now we only have 2 events to add. So, the two remaining threads loop and and another one succeeds. Now we have only one event waiting, which will succeed on the third go-around. Even if more events arrive in the meantime, progress will continue happening.

This will only fail if we have more than 1000 events arrive per second. I am pretty sure CouchDB / CPU usage will die first.

src/db/couchPushEvents.ts Outdated Show resolved Hide resolved
src/types/pushApiTypes.ts Show resolved Hide resolved
src/types/pushTypes.ts Outdated Show resolved Hide resolved
docs/demo.ts Outdated Show resolved Hide resolved
@swansontec swansontec force-pushed the william/v2-server branch 2 times, most recently from a6c6d93 to b452d0a Compare September 1, 2022 07:43
@swansontec swansontec merged commit 459ae0a into master Sep 8, 2022
@swansontec swansontec deleted the william/v2-server branch September 8, 2022 22:38
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.

2 participants