Skip to content

William/v2 server#42

Merged
swansontec merged 8 commits into
masterfrom
william/v2-server
Sep 8, 2022
Merged

William/v2 server#42
swansontec merged 8 commits into
masterfrom
william/v2-server

Conversation

@swansontec
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/db/couchPushEvents.ts
)
} catch (error) {
if (asMaybeConflictError(error) == null) throw error
await addEvent(connection, event, new Date(created.valueOf() + 1))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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.

Comment thread src/db/couchPushEvents.ts Outdated
Comment thread src/types/pushApiTypes.ts
Comment thread src/types/pushTypes.ts Outdated
Comment thread docs/demo.ts Outdated
@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