Re: RE: Re: Sqlite wrapper for Log package
| From: | Bertrand Mansion | Date: | Mon, 05 Jan 2004 11:39:13 +0000 |
| Subject: | Re: RE: Re: Sqlite wrapper for Log package | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24767@lists.php.net to get a copy of this message | ||
<urs@circle.ch> wrote :
> hello
>
> did you know that there is already an sqlite db wrapper in PEAR;
> wouldn't it make sense to base Log_sqlite on DB/sqlite too?
>
> to create a table is as simple as (untested):
>
> <?php
> require_once 'DB.php';
> require_once 'DB/sqlite.php';
> $db = DB::connect("sqlite://dummy:@localhost/log.db" );
> $db->query("CREATE TABLE log_table ( id INTEGER PRIMARY KEY NOT NULL,
> logtime NOT NULL, ident CHAR(16) NOT NULL, priority INT NOT NULL,
> message );" );
> $db->disconnect();
> ?>
I have run tests with both Log_sql and my Log_sqlite classes using Xdebug
profiler. Here are the results I got:
Log_file
--------------------------------------------------------------------
Opcode Compiling: 0.0462108850
Function Execution: 6.3916182518
Ambient Code Execution: 0.9997818470
Total Execution: 7.3914000988
Total Processing: 7.4376109838
Log_sql with sqlite PEAR::DB, sequence table already created
--------------------------------------------------------------------
Opcode Compiling: 0.1763240099
Function Execution: 54.5136159658
Ambient Code Execution: 0.9384210110
Total Execution: 55.4520369768
Total Processing: 55.6283609867
Log_sql with mysql PEAR::DB, sequence table already created, MyIsam
--------------------------------------------------------------------
Opcode Compiling: 0.0623170137
Function Execution: 42.9315174818
Ambient Code Execution: 0.9975454807
Total Execution: 43.9290629625
Total Processing: 43.9913799763
Log_sqlite, my log sqlite wrapper
--------------------------------------------------------------------
Opcode Compiling: 0.0933982134
Function Execution: 14.2798793316
Ambient Code Execution: 1.0633716583
Total Execution: 15.3432509899
Total Processing: 15.4366492033
The tests consisted in logging approx 5000 different events (with different
messages) in a loop. I am no expert of benchmarks so I don't know if that's
the best way (and my machine is very slow anyway).
My conclusion is that the sqlite wrapper in PEAR::DB makes sqlite slower
than mysql for this task. The difference between the first 2 results and the
last one shows that a "native" sqlite wrapper for Log is interesting, for
performance reasons and because of the nature of the job.
Furthermore, sqlite was here compiled with asserts (ie not with -DNDEBUG=1),
and inserts are done with PRAGMA default_synchronous = NORMAL which involves
a slowdown for data integrity in case of OS crash. So there is still room
for improvements... :)
If sqlite is going to be bundled into PHP because of its speed and its
lightweight, then it might deserve some special attention in PEAR packages
like log which depends on speed (same goes for Cache BTW).
Still, the file log is faster and will probably be even faster as more rows
are inserted in the database. That's why I recommend to split the sqlite
database into multiple smaller files.
Bertrand Mansion
Mamasam