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

[ws-server] Batch support #300

Merged
merged 15 commits into from
May 7, 2021
Merged

[ws-server] Batch support #300

merged 15 commits into from
May 7, 2021

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented May 4, 2021

Add batch request support for the websocket server. Continuation of #292.

Closes #277

TODO:

  • better tests
  • sort out error, switch from InvalidParams to CallError::Failed
  • benchmarks

http-server/src/module.rs Outdated Show resolved Hide resolved
test-utils/src/types.rs Outdated Show resolved Hide resolved
utils/src/server.rs Outdated Show resolved Hide resolved
http-server/src/module.rs Outdated Show resolved Hide resolved
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
ws-server/src/server.rs Outdated Show resolved Hide resolved
ws-server/src/server.rs Outdated Show resolved Hide resolved
@@ -47,7 +47,15 @@ impl RpcModule {
Box::new(move |id, params, tx, _| {
match callback(params) {
Ok(res) => send_response(id, tx, res),
Err(InvalidParams) => send_error(id, tx, JsonRpcErrorCode::InvalidParams.into()),
// TODO: this looks wonky...
Err(CallError::InvalidParams(InvalidParams)) => {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove this InvalidParams type and just use to InvalidParams variant,

perhaps link to #299

Copy link
Member

Choose a reason for hiding this comment

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

thus, if CallError would implement a trait or something JsonRpcErrorCode then you could just to err.to_error_code() or something similar

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

Looks overall good, not exactly sure of the overhead w.r.t spawning an unbounded channel per batch request.

Should be faster than reusing the existing channel and we "will" limit incoming requests based on payload size anyway so should be fine w.r.t OOM/DOS related issues.

@niklasad1
Copy link
Member

An additional bonus to this PR, would be to add integration tests for batch requests (both HTTP and WS)

Could address it in another PR also.

Return app-level error when call fails
@dvdplm dvdplm marked this pull request as ready for review May 6, 2021 10:34
@dvdplm dvdplm requested a review from insipx May 6, 2021 12:15
@dvdplm dvdplm self-assigned this May 6, 2021
Copy link
Contributor

@insipx insipx left a comment

Choose a reason for hiding this comment

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

Looks good other than small nits 👍

ws-server/src/server.rs Outdated Show resolved Hide resolved
ws-server/src/server.rs Outdated Show resolved Hide resolved
dvdplm and others added 2 commits May 7, 2021 12:38
Co-authored-by: Andrew Plaza <aplaza@liquidthink.net>
Co-authored-by: Andrew Plaza <aplaza@liquidthink.net>
@dvdplm dvdplm merged commit 4038e9e into master May 7, 2021
@dvdplm dvdplm deleted the dp-batch-support-ws branch May 7, 2021 10:44
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.

[servers]: batch request support
3 participants