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

⚡️ improve perf of ws client #17

Merged
merged 2 commits into from
Apr 4, 2024
Merged

Conversation

Odonno
Copy link
Contributor

@Odonno Odonno commented Sep 24, 2023

Performance improvement on the WS client implementation following the PR Marfusios/websocket-client#133

Note 1: Memory allocation reduced up to 50% on WS method calls

Note 2: WS method calls slightly faster (due to less memory allocation I suppose), around 1~3% faster than previous version

Note 3: WS "cold start" requires a significant amount of memory, due to the use of RecyclableMemoryStreamManager on the underlying websocket-client. Not surprising, as a WS client should make multiple calls in general. Also note that the RecyclableMemoryStreamManager is static, so it doesn't matter how many WS clients you use.

@Odonno Odonno marked this pull request as ready for review February 29, 2024 16:52
@codecov-commenter
Copy link

codecov-commenter commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.08%. Comparing base (cd66f74) to head (4401b34).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
- Coverage   69.14%   69.08%   -0.07%     
==========================================
  Files         110      110              
  Lines        4427     4431       +4     
  Branches      432      432              
==========================================
  Hits         3061     3061              
- Misses       1148     1151       +3     
- Partials      218      219       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Odonno
Copy link
Contributor Author

Odonno commented Feb 29, 2024

Updated benchmarks:

Cold Start

Method Mean Error StdDev Allocated
HttpConstructor 14.58 ms 0.272 ms 0.267 ms 8.68 KB
WsConstructor 15.81 ms 0.279 ms 0.261 ms 185.08 KB

Select

Method Mean Error StdDev Gen0 Gen1 Allocated
Http 15.672 ms 0.0517 ms 0.0432 ms - - 271.45 KB
HttpWithClientFactory 15.695 ms 0.0866 ms 0.0768 ms - - 267.5 KB
WsText 7.110 ms 0.0933 ms 0.0827 ms 62.5000 31.2500 1993.8 KB
WsBinary NA NA NA NA

Create

Method Mean Error StdDev Gen0 Allocated
Http 14,798.4 us 141.09 us 117.81 us - 51.82 KB
HttpWithClientFactory 14,967.4 us 270.75 us 240.02 us - 52.4 KB
WsText 289.2 us 4.39 us 3.90 us 2.4414 45.89 KB
WsBinary NA NA NA NA NA

Upsert

Method Mean Error StdDev Gen0 Allocated
Http 15,043.8 us 122.41 us 114.50 us - 23.5 KB
HttpWithClientFactory 15,162.6 us 273.59 us 242.53 us - 25.43 KB
WsText 251.8 us 3.60 us 3.37 us 0.9766 18.64 KB
WsBinary NA NA NA NA NA

Delete

Method Mean Error StdDev Allocated
Http 14,469.3 us 118.94 us 105.44 us 6.15 KB
HttpWithClientFactory 14,385.1 us 107.84 us 100.88 us 7.34 KB
WsText 150.9 us 2.17 us 2.03 us 3.51 KB
WsBinary NA NA NA NA

Query

Method Mean Error StdDev Gen0 Gen1 Allocated
Http 22.681 ms 0.1913 ms 0.1790 ms 62.5000 31.2500 2.57 MB
HttpWithClientFactory 22.513 ms 0.0889 ms 0.0742 ms 62.5000 31.2500 2.64 MB
WsText 8.750 ms 0.0479 ms 0.0448 ms 62.5000 31.2500 2.63 MB
WsBinary NA NA NA NA

Scenario

Method Mean Error StdDev Gen0 Allocated
Http 181.609 ms 2.3738 ms 2.1043 ms - 134.09 KB
HttpWithClientFactory 182.404 ms 0.8664 ms 0.7235 ms - 151.79 KB
WsText 3.080 ms 0.0592 ms 0.0634 ms 3.9063 85.54 KB
WsBinary NA NA NA NA

@kearfy kearfy merged commit 453a090 into surrealdb:main Apr 4, 2024
2 checks passed
@Odonno Odonno deleted the perf/ws-client branch April 4, 2024 20: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.

3 participants