Skip to content Skip to sidebar Skip to footer

Why Cant We Share Cassandra Session Initialised In Parent Process To Child Process(python Driver)?

I am developing a multi-process application and using cassandra, I have a single session opened at the begining of the server and i want to share the session to other processes.I j

Solution 1:

Yes, It is possible and recommended to use one session 4 simple rules when using the DataStax drivers for Cassandra

When using one of the DataStax drivers for Cassandra, either if it’s C#, Python, or Java, there are 4 simple rules that should clear up the majority of questions and that will also make your code efficient:

  1. Use one Cluster instance per (physical) cluster (per application lifetime)
  2. Use at most one Session per keyspace, or use a single Session and explicitely specify the keyspace in your queries
  3. If you execute a statement more than once, consider using a PreparedStatement
  4. You can reduce the number of network roundtrips and also have atomic operations by using Batches

Source http://www.datastax.com/dev/blog/4-simple-rules-when-using-the-datastax-drivers-for-cassandra

Solution 2:

No, its not recommended.

Quoting the official datastax documentation:

Be sure to never share any Cluster, Session, or ResponseFuture objects across multiple processes. These objects should all be created after forking the process, not before.

Source: https://datastax.github.io/python-driver/performance.html#multiprocessing

Post a Comment for "Why Cant We Share Cassandra Session Initialised In Parent Process To Child Process(python Driver)?"