1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | Coro::Mysql - let other threads run while doing mysql requests |
3 | Coro::Mysql - let other threads run while doing mysql/mariadb requests |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use Coro::Mysql; |
7 | use Coro::Mysql; |
8 | |
8 | |
… | |
… | |
17 | This module replaces the I/O handlers for a database connection, with the |
17 | This module replaces the I/O handlers for a database connection, with the |
18 | effect that "patched" database handles no longer block the all threads of |
18 | effect that "patched" database handles no longer block the all threads of |
19 | a process, but only the thread that does the request. |
19 | a process, but only the thread that does the request. |
20 | |
20 | |
21 | This can be used to make parallel sql requests using Coro, or to do other |
21 | This can be used to make parallel sql requests using Coro, or to do other |
22 | stuff while mysql is rumbling in the background. |
22 | stuff while mariadb is rumbling in the background. |
23 | |
23 | |
24 | =head2 CAVEAT |
24 | =head2 CAVEAT |
25 | |
25 | |
26 | Note that this module must be linked against exactly the same (shared, |
26 | Note that this module must be linked against exactly the same (shared, |
27 | possibly not working with all OSes) F<libmysqlclient> library as |
27 | possibly not working with all OSes) F<libmariadb>/F<libmysqlclient> |
28 | DBD::mysql, otherwise it will not work. |
28 | library as L<DBD::mysql>, otherwise it will not work. |
29 | |
|
|
30 | Also, this module requires a header file that apparently isn't installed |
|
|
31 | everywhere (F<violite.h>), and therefore comes with it's own copy, which |
|
|
32 | might or might not be compatible to the F<violite.h> of your library - |
|
|
33 | when in doubt, make sure all the libmysqlclient header files are installed |
|
|
34 | and delete the F<violite.h> header that comes with this module. |
|
|
35 | |
|
|
36 | On the good side, this module does a multitude of checks to ensure that |
|
|
37 | the libray versions match on the binary level, so on incompatibilities you |
|
|
38 | should expect an exception when trying to unblock a handle, rather than |
|
|
39 | data corruption. |
|
|
40 | |
29 | |
41 | Also, while this module makes database handles non-blocking, you still |
30 | Also, while this module makes database handles non-blocking, you still |
42 | cannot run multiple requests in parallel on the same database handle. If |
31 | cannot run multiple requests in parallel on the same database handle. If |
43 | you want to run multiple queries in parallel, you have to create multiple |
32 | you want to run multiple queries in parallel, you have to create multiple |
44 | database connections, one for each thread that runs queries. Not doing |
33 | database connections, one for each thread that runs queries. Not doing |
… | |
… | |
176 | or die $DBI::errstr; |
165 | or die $DBI::errstr; |
177 | |
166 | |
178 | Coro::on_enter { $PApp::SQL::DBH = $dbh }; |
167 | Coro::on_enter { $PApp::SQL::DBH = $dbh }; |
179 | |
168 | |
180 | $cb->(); |
169 | $cb->(); |
181 | } |
170 | } |
182 | |
171 | |
183 | This function makes it possible to easily use L<PApp::SQL> with |
172 | This function makes it possible to easily use L<PApp::SQL> with |
184 | L<Coro::Mysql>, without worrying about database handles. |
173 | L<Coro::Mysql>, without worrying about database handles. |
185 | |
174 | |
186 | # now start 10 threads doing stuff |
175 | # now start 10 threads doing stuff |
… | |
… | |
211 | |
200 | |
212 | This module was initially hacked together within a few hours on a long |
201 | This module was initially hacked together within a few hours on a long |
213 | flight to Malaysia, and seems to have worked ever since, with minor |
202 | flight to Malaysia, and seems to have worked ever since, with minor |
214 | adjustments for newer libmysqlclient libraries. |
203 | adjustments for newer libmysqlclient libraries. |
215 | |
204 | |
|
|
205 | Well, at least until mariadb introduced the new Pluggable Virtual IO API |
|
|
206 | in mariadb 10.3, which changed and broke everything. On the positive |
|
|
207 | side, the old system was horrible to use, as many GNU/Linux distributions |
|
|
208 | forgot to include the required heaqder files and there were frequent small |
|
|
209 | changes, while the new PVIO system seems to be "official" and hopefully |
|
|
210 | better supported. |
|
|
211 | |
216 | =head1 AUTHOR |
212 | =head1 AUTHOR |
217 | |
213 | |
218 | Marc Lehmann <schmorp@schmorp.de> |
214 | Marc Lehmann <schmorp@schmorp.de> |
219 | http://home.schmorp.de/ |
215 | http://home.schmorp.de/ |
220 | |
216 | |