C calls are not interruptible
Hmm...?? How do we explain the followings:
I made a demostration delibrately make MySql execute to a Maximum time of 5 sec, then set a timeout alarm of 3 sec in eval{} to prevent MySql execution more than 3 sec.
To my surprise, timeout alarm in eval{} stops MySql execution exactly at 3 sec. COSISTENTLY
The followings is the demonstration script:
#!/usr/bin/perl
$max_time = 5;
$timeout = 3;
use DBI;
print "Content-type: text/html\n\n";
sub do_counter {
$time1 = time;
$time2 = time;
$counter = 0;
$time_ran = $time2 - $time1;
$dbh=DBI->connect("dbi:mysql:$database:localhost","username","
+password");
$query="SELECT name FROM test";
$sth=$dbh->prepare($query);
$sth->execute();
while ( @row = $sth->fetchrow_array ) {
while($time_ran <= $max_time) {
$conter++;
$time2 = time;
$time_ran = $time2 - $time1;
}
}
$sth->finish;
$dbh->disconnect ||die("Couldn't disconnect to database!\n");
}
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
&do_counter;
alarm 0;
};
if($@) {
print "$@, Time Ran: $time_ran, Counter: $conter\n";
exit;
}
print "Time Ran: $time_ran, Counter: $conter\n";
exit;
As you can see, I delibrately make a counter loop inside MySql's while ( @row = $sth->fetchrow_array ) loop. The counter loop can run to a $max_time of 5 sec. before it stops.
In the eva{} I set a timeout alarm of 3 sec. to stop MySql execution from going over 3 sec.
When I ran the above script, I got the following results consistently:
alarm, Time Ran: 3, Counter: 3341554
alarm, Time Ran: 3, Counter: 3416456
These results show that alarm in eval{} has stopped MySql execution in 3 sec.
Can we not say then that alarm has interrupted MySql C Calls (e.g. calls to the db driver), contrary to what you said?
You can do the same demostration with the above script by doing the followings:
1) Create a table TEST with a single column: name CHAR(30) NOT NULL
2) Enter 3 names, like John, Paul, Mary in the table.
3) Run the above script.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.