ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro-Mysql/Mysql.pm
(Generate patch)

Comparing Coro-Mysql/Mysql.pm (file contents):
Revision 1.13 by root, Thu Oct 11 03:18:31 2012 UTC vs.
Revision 1.23 by root, Mon Mar 4 05:44:43 2019 UTC

1=head1 NAME 1=head1 NAME
2 2
3Coro::Mysql - let other threads run while doing mysql requests 3Coro::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
17This module replaces the I/O handlers for a database connection, with the 17This module replaces the I/O handlers for a database connection, with the
18effect that "patched" database handles no longer block the all threads of 18effect that "patched" database handles no longer block the all threads of
19a process, but only the thread that does the request. 19a process, but only the thread that does the request.
20 20
21This can be used to make parallel sql requests using Coro, or to do other 21This can be used to make parallel sql requests using Coro, or to do other
22stuff while mysql is rumbling in the background. 22stuff while mariadb is rumbling in the background.
23 23
24=head2 CAVEAT 24=head2 CAVEAT
25 25
26Note that this module must be linked against exactly the same (shared, 26Note that this module must be linked against exactly the same (shared,
27possibly not working with all OSes) F<libmysqlclient> library as 27possibly not working with all OSes) F<libmariadb>/F<libmysqlclient>
28DBD::mysql, otherwise it will not work. 28library as L<DBD::mysql>, otherwise it will not work.
29
30Also, this module requires a header file that apparently isn't installed
31everywhere (F<violite.h>), and therefore comes with it's own copy, which
32might or might not be compatible to the F<violite.h> of your library -
33when in doubt, make sure all the libmysqlclient header files are installed
34and delete the F<violite.h> header that comes with this module.
35
36On the good side, this module does a multitude of checks to ensure that
37the libray versions match on the binary level, so on incompatibilities you
38should expect an exception when trying to unblock a handle, rather than
39data corruption.
40 29
41Also, while this module makes database handles non-blocking, you still 30Also, while this module makes database handles non-blocking, you still
42cannot run multiple requests in parallel on the same database handle. If 31cannot run multiple requests in parallel on the same database handle. If
43you want to run multiple queries in parallel, you have to create multiple 32you want to run multiple queries in parallel, you have to create multiple
44database connections, one for each thread that runs queries. Not doing 33database connections, one for each thread that runs queries. Not doing
105 94
106sub readable { &Coro::Handle::FH::readable } 95sub readable { &Coro::Handle::FH::readable }
107sub writable { &Coro::Handle::FH::writable } 96sub writable { &Coro::Handle::FH::writable }
108 97
109BEGIN { 98BEGIN {
110 our $VERSION = '1.2'; 99 our $VERSION = '2.0';
111 100
112 require XSLoader; 101 require XSLoader;
113 XSLoader::load Coro::Mysql::, $VERSION; 102 XSLoader::load Coro::Mysql::, $VERSION;
114} 103}
115 104
145 if (AnyEvent::detect ne "AnyEvent::Impl::EV" || !_use_ev) { 134 if (AnyEvent::detect ne "AnyEvent::Impl::EV" || !_use_ev) {
146 require Coro::Handle; 135 require Coro::Handle;
147 $fh = Coro::Handle::unblock ($fh); 136 $fh = Coro::Handle::unblock ($fh);
148 } 137 }
149 138
150 _patch $sock, $DBH->{sockfd}, $DBH->{mysql_clientversion}, $fh, tied ${$fh}; 139 _patch $sock, $DBH->{sockfd}, $DBH->{mysql_clientversion}, $fh, tied *$$fh;
151 } 140 }
152 141
153 $DBH 142 $DBH
154} 143}
155 144
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
183This function makes it possible to easily use L<PApp::SQL> with 172This function makes it possible to easily use L<PApp::SQL> with
184L<Coro::Mysql>, without worrying about database handles. 173L<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
212This module was initially hacked together within a few hours on a long 201This module was initially hacked together within a few hours on a long
213flight to Malaysia, and seems to have worked ever since, with minor 202flight to Malaysia, and seems to have worked ever since, with minor
214adjustments for newer libmysqlclient libraries. 203adjustments for newer libmysqlclient libraries.
215 204
205Well, at least until mariadb introduced the new Pluggable Virtual IO API
206in mariadb 10.3, which changed and broke everything. On the positive
207side, the old system was horrible to use, as many GNU/Linux distributions
208forgot to include the required heaqder files and there were frequent small
209changes, while the new PVIO system seems to be "official" and hopefully
210better 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines