gocql - one session per keyspace?

11 views
Skip to first unread message

Martin Brzenska

<m.brzenska@xovi.com>
unread,
Nov 26, 2021, 8:55:01 AM11/26/21
to ScyllaDB users
Hello scylla friends,

i have a GOlang service and a ScyllaDB cluster with several keyspaces.
The service reads and writes to up to 4 keyspaces at a time. When the service boots up, it creates a session instance for each keyspace.

The question is: is it better to have a seperate session instance for each keyspace or should i refactor the code to use one session for all keyspaces?

But this article sounds it could be not a good idea ("You might be tempted to open a separate session for each keyspace...").

Thank you
Martin

Martin Sucha

<martin.sucha@kiwi.com>
unread,
Nov 26, 2021, 9:27:58 AM11/26/21
to scylladb-users@googlegroups.com
Hello Martin,

On Fri, Nov 26, 2021 at 2:55 PM 'Martin Brzenska' via ScyllaDB users <scyllad...@googlegroups.com> wrote:
i have a GOlang service and a ScyllaDB cluster with several keyspaces.
The service reads and writes to up to 4 keyspaces at a time. When the service boots up, it creates a session instance for each keyspace.

The question is: is it better to have a seperate session instance for each keyspace or should i refactor the code to use one session for all keyspaces?

If you have four sessions to the same cluster, you will have 4x the amount of network connections open as each session manages its own connection pools.

In general I'd say it's better to use just one session per cluster unless you need separate sessions for some other reason (like using multiple users).
While there is only one default keyspace per session in gocql, you can specify the keyspace for each query explicitly.

Martin


This email, including attached files, may contain confidential information and is intended only for the use of the individual and/or entity to which it is addressed. If you are not the intended recipient, disclosure, copying, use, or distribution of the information included in this email and/or in its attachments is prohibited.
If you have received it by mistake, please do not read, copy or use it, or disclose its contents to others. Please notify the sender that you have received this email by mistake by replying to the email, and then delete the email and any copies and attachments of it. Thank you.
Reply all
Reply to author
Forward
0 new messages