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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.