Replies: 12 comments 10 replies
-
You can create You can not create a connection Also, migrations and the schema builder can be called only from the main thread (or any thread but only one thread at a time), the main reason are
We have to follow the same rules and restrictions as the
Yes, it's possible, you can create a connection pool. |
Beta Was this translation helpful? Give feedback.
-
The The Use |
Beta Was this translation helpful? Give feedback.
-
You don't have Qt database driver ready, to what DB you are trying to connect and which OS? |
Beta Was this translation helpful? Give feedback.
-
Yeah, you are right, connection names have to be unique across threads if I correctly remember. |
Beta Was this translation helpful? Give feedback.
-
You can also try |
Beta Was this translation helpful? Give feedback.
-
I have it working on one thread, I’ve moved things around so there is only one instance of database manager ever called, but in order to get the database drivers loaded I have to use QApplication::addLibraryPath(“xyz”)I’m wondering if this is also thread specific. I’ll try again in a bit.Sent from my iPhoneOn Mar 11, 2023, at 12:15 PM, Silver Zachara ***@***.***> wrote:
You don't have Qt database driver ready, to what DB you are trying to connect and which OS?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
TinyOrmPlayground calls ~1500 queries against 3 databases in 3 threads, 500 against MySQL, 500 PostgreSQL, and 500 SQLite at the same time. The performance gain was amazing when I implemented this. But I have never tried to create more connections from different threads to one or to the same database though. |
Beta Was this translation helpful? Give feedback.
-
This works. Connection names must be unique across all threads, but you can create any combination of anything else, drivers, threads, at the same time. I'll just need to write wrappers to create unique names, and remove them when a thread has ended. Hopefully the build up/tear down isn't too much of a performance hit. It's unfortunate that as great as the Qt library is, they've really killed SQL usability here with these thread limitations. Though, I've run into some other issues with TinyORM while testing this since I'm now required to use This works
This also works This does not There is no method available. Additionally, while using
The connection doesn't persist, and it tries to load from the database again instead of grabbing off the the model that's already been found, causing it to crash like before. |
Beta Was this translation helpful? Give feedback.
-
To have
Nice catch friend, really 👍, this is a bug and not a simple one, omg. how is possible it never happened to me, I'm invoking and compiling the whole library 100 times per day and I never saw it. 😲 |
Beta Was this translation helpful? Give feedback.
-
I have fixed it and pushed a new
Also, how can I reproduce this? |
Beta Was this translation helpful? Give feedback.
-
I have checked this morning how threading works in the libpq and MySQL c API. From
From
From
The But it would have to be tested first if everything works correctly, I think it would be a lot of work to make it real. TinyORM doesn't have a problem with it, I have checked all globals and it would be totally possible, it's treated in tinyorm code. |
Beta Was this translation helpful? Give feedback.
-
The most funning thing is that Qt is talking about restrictions in third-party libraries, but the biggest restriction is on their side .😎 From Qt docs:
|
Beta Was this translation helpful? Give feedback.
-
On the page: https://www.tinyorm.org/database/getting-started
It states that multithreading support exists, excluding schema builder and migrations, but immediately after that, it says that DB::connection must be used in the thread that it was created in, which means that multi-threading support doesn't really exist at all. Maybe you mean that creating connections in multiple threads running simultaneously is supported? Though I may be misunderstanding.
Additionally, when creating multiple DB::create methods from multiple threads throws an exception
Only one instance of DatabaseManager is allowed per process.
Can you clarify on the specifics?
I would imagine that if each thread is capable of handling its own connections and you can have multiple threads, each with its own connection definitions, it must be possible to create a connection pool at a higher level and track if it's currently in use, lock it, and use it when it is not. Creating a large number of connections to SQL servers is an expensive operation rather than utilizing a connection pool where X number of connections can stay open, and new ones created when needed.
Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions