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

Docs: Add recommendations about Session usage. #914

Merged
merged 6 commits into from
Jan 24, 2024

Conversation

Lorak-mmk
Copy link
Collaborator

#216 showed that best practices of Session usage are not obvious and should be stated in documentation.
This PR adds the relevant section that explains how to use it in order to not decrease performance.

Fixes: #216

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@Lorak-mmk Lorak-mmk requested a review from piodul January 14, 2024 20:45
docs/source/connecting/connecting.md Outdated Show resolved Hide resolved
docs/source/connecting/connecting.md Outdated Show resolved Hide resolved
docs/source/connecting/connecting.md Outdated Show resolved Hide resolved
@@ -35,6 +35,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
After successfully connecting to some specified node the driver will fetch topology information about
other nodes in this cluster and connect to them as well.

Driver maintains this pool of connections and each connection is capable of handling multiple requests in parallel. Driver will also route the request to node / shard that actually owns the data (unless load balancing policy that you use doesn't support it).
For those reasons, we recommend to use one instance of `Session` per application.
Creating short-lived `Session`'s (e.g. `Session` per request) is extremely discouraged and will result in great performance penalties because creating a `Session` is a costly process - it requires estabilishing a lot of TCP connections.
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO "extremely" is too strong of a word here. There are cases where short sessions make sense, e.g. an administrative tool that connects only to execute a single statement. Of course, creating multiple sessions over the course of the application is wasteful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

strongly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I change to strongly, if that's also too strong I'll rewrite this sentence differently

Copy link
Collaborator

Choose a reason for hiding this comment

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

"Strongly" sounds better to me as well. I was mostly concerned about the "short-lived" sessions given the use cases for them I mentioned in my previous comment, but with the added warning about using only one session per application I think it looks OK now.

docs/source/connecting/connecting.md Outdated Show resolved Hide resolved
@Lorak-mmk Lorak-mmk changed the title Docs: Add recommendations about Sessions usage. Docs: Add recommendations about Session usage. Jan 23, 2024
@Lorak-mmk Lorak-mmk force-pushed the session-usage-recommendations branch from 2fc8656 to 95330ed Compare January 23, 2024 17:09
@Lorak-mmk
Copy link
Collaborator Author

v2:

  • Addressed review comments
  • Changed formatting so that new section doesn't render as a block of text
  • Added an adminition in order to make this section easier to notice. How it looks in Scylla docs:
    image
    and in mdbook:
    image
    This required changing preprocessor script a bit.
  • Split the file into sections becaue there was too much contiguous text

@Lorak-mmk Lorak-mmk requested a review from piodul January 23, 2024 17:13
@Lorak-mmk
Copy link
Collaborator Author

v3: Fixed typo in preprocessor script

@Lorak-mmk Lorak-mmk force-pushed the session-usage-recommendations branch from 85cac1f to f359ed1 Compare January 24, 2024 16:08
@piodul piodul merged commit 4feb6fb into scylladb:main Jan 24, 2024
9 checks passed
@Lorak-mmk Lorak-mmk mentioned this pull request Feb 1, 2024
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.

Session Clone
2 participants