You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new in Mojolicious and playing around with this simple application to return rows from database. It seems to work fine for a single request, however when I use "xargs -n 1 -P 4" to run curl in parallel processes I start seeing "500 Internal Server Error" or "Empty reply from server".
The debug message in the log shows a number of "ORA-01002: fetch out of sequence" and "Worker 101864 has no heartbeat (50 seconds), restarting".
Really appreciate any guidance of what mistake that I made here.
use Mojolicious::Lite -signatures;
use Mojo::Promise;
use DBI;
my$dbh = DBI->connect(...);
app->config( hypnotoad=> { listen=> ['http://*:3000'], workers=> 4, proxy=> 1 });
helper select=>sub {
my$c = shift;
my ($column1) = @_;
my$query = <<~"END";
SELECT * FROM mytable WHERE column1 = :column1ENDmy$sth = $dbh->prepare($query) ordo {
$promise->reject("Failed to prepare SQL: " . $dbh->errstr);
return;
};
$sth->bind_param(":column1", $column1);
$sth->execute() ordo {
$promise->reject("Unable to execute SQL: " . $dbh->errstr);
return;
};
# Fetch all rows from the result setmy$data = $sth->fetchall_arrayref({});
$sth->finish();
return$data;
};
get '/foo/bar'=>sub {
my$c = shift;
my$column1 = $c->param('column1');
my$promise = Mojo::Promise->new;
Mojo::IOLoop->next_tick( sub {
my$data = $c->select( $column1 );
my@records = map { join('|', $_->{column1}, $_->{column2}) } $data->@*;
my$ret_ref = JSON->new->utf8(1)->pretty(1)->encode( { 'MYRESULT'=> \@records });
$c->render(text=>$ret_ref, format=>'json');
# Return the data as pretty JSON$promise->resolve;
});
$promise->catch( sub {
my ($err) = @_;
$c->render(
status=> 500,
json=> { zzzerror=>$err }
);
});
$promise->wait;
};
app->start;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am new in Mojolicious and playing around with this simple application to return rows from database. It seems to work fine for a single request, however when I use
"xargs -n 1 -P 4"
to run curl in parallel processes I start seeing"500 Internal Server Error"
or"Empty reply from server"
.The debug message in the log shows a number of
"ORA-01002: fetch out of sequence"
and"Worker 101864 has no heartbeat (50 seconds), restarting"
.Really appreciate any guidance of what mistake that I made here.
Beta Was this translation helpful? Give feedback.
All reactions