rjmcguire / cassandra-d

D language cassandra client
MIT License
10 stars 8 forks source link

Project Direction #3

Open gronka opened 9 years ago

gronka commented 9 years ago

Hi, I've been using Cassandra for a personal project, and I recently started porting my project to D within vibe.d.

I was wondering about the direction of this project, as I'm likely to use it a lot and to contribute when I'm able.

1) I'm looking at DataStax's C++ driver, and I noticed this line: It’s generally better to create a single session with more I/O threads than multiple sessions with a smaller number of I/O threads. It seems to me, as this project currently stands, it requires a fresh connectCassandraDB instance to be started per vibe.d thread/fiber (at least per client http request).. Am I wrong? (I'll admit I need to learn about the thread/fiber difference and how they work in vibe.d.) 2) Regarding the answer to question 1, where is a good place to initialize the connection in vibe.d? It does seem as though a single connection would save much latency, but I'm not sure if this project is thread-safe yet (which I would be happy to work on as I learn more). 3) Are there any guiding design principles you would prefer? If I was to start a driver like this from scratch, I would likely use the DataStax ones as guides/inspiration. Would you support that?

Thank you

gronka commented 9 years ago

Oh - I'm looking at the class Connection now. Do these lines effectively make the driver thread safe?

import vibe.core.connectionpool : ConnectionPool;
ConnectionPool!Connection m_connections;

m_connections = new ConnectionPool!Connection(&createConnection);

Looking at vibe's mongo.d, it seems that this the connectionpool makes the function fiber safe. But I'm not entirely sure what I should be concerned with in regards to threads yet.

Edit: so it seems as though vibe.d also handles thread safety.

rjmcguire commented 8 years ago

Hi,

I hadn't noticed any issue notifications for this repo, until now.

This library is not "technically" thread-safe and neither is vibe.d, for example it is possible to make a vibe.d application that would try to read from a cassandra connection and have a separate Thread read data from the buffer while the data is busy being written into the buffer inside cassandrad.

So no not thread-safe, but if you use the library like a normal database connection and don't hand the connection reference between threads that both use it or put it in a global shared variable, you will not have issues.

In what way would you be using the connection that you need it to be thread-safe?

rjmcguire commented 8 years ago

Regarding your first question, it does have a connection pool and the connections will be re-used. I can't remember if I completed multiple sessions over a single connection yet though.

gronka commented 8 years ago

Oh! Thanks for the information.

I enjoy coding in D, and have a project that I would like to move to D, but it relies heavily on Cassandra. I keep going back and forth on if I want to make the time investment haha.

I had some threads on the vibe.d forums too which gave me a better idea of the state of threading in vibe.d - although I'd have to review them, since it was about a year ago.