I've written a Parallel::ForkManager reproduction script in hopes others can review/test and provide feedback. It doesn't involve any convoluted event code.
I created a simple database by running sqlite3 test.db < test.sql where test.sql consists of:
DROP TABLE IF EXISTS test; CREATE TABLE test ( id VARCHAR(50), value VARCHAR(20) ); INSERT INTO test VALUES ('test', 0);
Here is the code. Note that lowering the num of forks, and/or tweaking with sleeping will evade the issue... for a period only. It eventually creeps back in. The code below breaks nearly immediately (on my Raspberry Pi 3):
use warnings; use strict; use DBI; use Parallel::ForkManager; my $dbh = DBI->connect( "dbi:SQLite:dbname=test.db", "", "", {RaiseError => 1} ) or die $DBI::errstr; my $pm = Parallel::ForkManager->new(20); for (1..20){ $pm->start and next; my $interval = $_ / 10; while (1){ dbwrite($dbh, $interval); #print "$interval\n"; } } while(1){ my $sth = $dbh->prepare( "SELECT * FROM test WHERE id=?;" ); $sth->execute('test'); my $val = $sth->fetchrow_hashref()->{value}; #sleep 1; } sub dbwrite { my ($dbh, $interval) = @_; my $sth = $dbh->prepare( 'UPDATE test SET value=? WHERE id="test;"' ); $sth->execute($interval); };
On my more powerful laptop with an SSD disk, it takes ~10 seconds to break. Now, my application doesn't process nearly as fast as this script does. That said, it still isn't good, and I need to find a reliable solution.
Are there any reasonable fixes for this, or should I instead be looking at using a MySQL database on a remote server? DB read/writes in the real app I'm writing happen at most, every second, give or take.
I'd really, really like to avoid using an external DB if possible; I want this app to be self-contained. I can't use a memory db (ie. I don't know HOW to share a memory db between different processes, so any pointers here that I can test will be quite welcome as well).
Thanks for all the feedback Monks.
-stevieb
In reply to Re: DBD::SQLite "file is encrypted or is not a database" in running application (repro code)
by stevieb
in thread [SOLVED]: DBD::SQLite "file is encrypted or is not a database" in running application
by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |