codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.54k stars 341 forks source link

Java SDK connection pooling #678

Closed srinisubramanian closed 3 years ago

srinisubramanian commented 3 years ago

What is the recommendation for connection pooling using the Java SDK?

Can we have single instance of ImmuClient and login/logout multiple times? Is it threadsafe?

What is the recommendation for reuse in a Wildfly server environment. Web requests will result in data being populated in ImmuDb.

jeroiraz commented 3 years ago

Hi @srinisubramanian, java sdk is thread-safe. It means a single instance of immuClient can be used from multiple threads, such in this unit test: https://github.com/codenotary/immudb4j/blob/master/src/test/java/io/codenotary/immudb4j/MultithreadTest.java

immudb is thread-safe as well, so you can create a pool of client connections.

Please lets us know if you experience any issue or you need some guidance

srinisubramanian commented 3 years ago

Hi @jeroiraz

Thanks for the guidance.

  1. From a performance standpoint what is recommended? A single ImmuClient or multiple?

  2. Similar to the test thread eg., can login on a ImmuClient be done once and set/get called? Or each usage needs a login/logout pair?

Thanks. Excited to get this into our solution

jeroiraz commented 3 years ago

Using multiple immuClients may boost performance given the grpc stub is blocking.

immudb is able to concurrently process transactions whenever possible, so having multiple clients concurrently submitting transactions result convenient and safe.

multiple operations can be requested as part of the same client session, no need to re-login, currently only it's needed to handle auth token expiration (60min duration).

srinisubramanian commented 3 years ago

Thanks @jeroiraz One last question. Will tge isConnected() method be a sufficient check if the authentication is valid? How does one determine if a reauthenticate is necessary?

Thanks

jeroiraz commented 3 years ago

currently, it the operation will raise an exception and you may need to check if the token as expired. Some error refinement is still under progress