torden/php-mdbm

PHP-mdbm is a PHP binds to the MDBM.

Installs: 3 965

Dependents: 0

Suggesters: 0

Security: 0

Stars: 7

Watchers: 5

Forks: 2

Open Issues: 0

Language:C

v0.1.2 2022-09-01 03:25 UTC

README

  • PHP-mdbm is a PHP binds to Yahoo! MDBM C API.
  • MDBM is a super-fast memory-mapped key/value store.
  • MDBM is an ndbm work-alike hashed database library based on sdbm which is based on Per-Aake Larson’s Dynamic Hashing algorithms.
  • MDBM is a high-performance, memory-mapped hash database similar to the homegrown libhash.
  • The records stored in a mdbm database may have keys and values of arbitrary and variable lengths.

Table of Contents

API

Almost Useful APIs Support.

Not Supported APIs

Unfortunately, the following list are not supported on now.

If you want them, please feel free to raise an issue

Deprecated APIs

Only a V2 implementation

Support Two Versions Compatibility

PHP

MDBM

Install

MDBM

php-mdbm

Use the composer (packagist)

See the composer documentation for use composer

composer require torden/php-mdbm

Use the source code

git clone https://github.com/torden/php-mdbm
Or Download the tarball (tag or release)
wget https://github.com/torden/php-mdbm/archive/vX.X.X.tar.gz
tar xvzf vX.X.X.tar.gz
Compile
cd php-mdbm/src/
$PHP_INSTALLED_PATH/bin/phpize
./configure --with-php-config=$PHP_INSTALLED_PATH/bin/php-config --with-mdbm=/usr/local/mdbm/
make
#make test TESTS='-q -m'
#make test TESTS='-q'
make install
Configuration
echo "extension=mdbm.so" >> php.ini
Check
$PHP_INSTALLED_PATH/bin/php -i | fgrep -i mdbm
...
mdbm
MDBM Support => enable
MDBM API Version => 4
PHP MDBM Version => 0.1.0
...

Example

See the documentation for more details.

Benchmark

The following is results of PHP-mdbm vs PHP SQlite3 benchmarks for simple data storing and random fetching.

See the Source Code.

Prepare for a Benchmark

cd php-mdbm/src/benchmark/
composer install

Spec

Host

VM

Software

Simple INSERTs

php src/mdbm_simple_store.php -live
 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-21 01:33:02

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               2.86 μs |    0.00 KB |    2.00 MB
 > mdbm store(number, number) :: 100,000                       297.88 ms |    0.00 KB |    2.00 MB
 > mdbm store(string, string) :: 100,000                       329.36 ms |    0.00 KB |    2.00 MB
 > mdbm store(number, number) :: 1,000,000                       2.94  s |    0.00 KB |    2.00 MB
 > mdbm store(string, string) :: 1,000,000                       3.36  s |    0.00 KB |    2.00 MB
 > mdbm store(number, number):: 10,000,000                       70.4  s |    0.00 KB |    2.00 MB
 > mdbm store(string, string) :: 10,000,000                    125.46  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-21 01:36:25    202.78  s      0.00 KB      2.00 MB

Simple Random FETCHs

php src/mdbm_simple_fetch.php -live
 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-21 01:37:49

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > mdbm random fetch(number) :: 100,000                        140.18 ms |    0.00 KB |    2.00 MB
 > mdbm random fetch(string) :: 100,000                        161.95 ms |    0.00 KB |    2.00 MB
 > mdbm random fetch(number) :: 1,000,000                        1.44  s |    0.00 KB |    2.00 MB
 > mdbm random fetch(string) :: 1,000,000                        1.63  s |    0.00 KB |    2.00 MB
 > mdbm random fetch(number):: 10,000,000                       15.07  s |    0.00 KB |    2.00 MB
 > mdbm random fetch(number) :: 10,000,000                      16.97  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-21 01:38:24     35.42  s      0.00 KB      2.00 MB

Simple Random FETCHs with Use the Preload API

php src/mdbm_simple_preload_fetch.php -live
 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-21 01:39:36

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number) :: 100,000               138.52 ms |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(string) :: 100,000               154.26 ms |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number) :: 1,000,000                1.4  s |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(string) :: 1,000,000               1.58  s |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number):: 10,000,000              14.83  s |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number) :: 10,000,000             16.73  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-21 01:40:11     34.83  s      0.00 KB      2.00 MB

SQLite3

Simple INSERTs

php src/sqlite3_simple_store.php -live
PRAGMA synchronous=OFF;
pragma journal_mode = wal;
Transaction(BEGIN,COMMIT)

 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-22 00:44:56

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > sqlite3 insert(number, number) :: 100,000                    761.78 ms |    0.00 KB |    2.00 MB
 > sqlite3 insert(string, string) :: 100,000                      1.17  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(number, number) :: 1,000,000                    7.93  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(string, string) :: 1,000,000                   12.29  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(number, number):: 10,000,000                   80.24  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(string, string) :: 10,000,000                 127.54  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-22 01:00:25    229.93  s      0.00 KB      2.00 MB

Simple Random FETCHs

php src/sqlite3_simple_fetch.php -live
PRAGMA synchronous=OFF;
pragma journal_mode = wal;

 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-22 01:23:53

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(number) :: 100,000                       2.16  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(string) :: 100,000                       3.16  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(number) :: 1,000,000                    25.94  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(string) :: 1,000,000                    34.84  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(number):: 10,000,000                   275.47  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(string) :: 10,000,000                  397.42  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-22 01:36:12    738.99  s      0.00 KB      2.00 MB

Link

Please feel free. I hope it is helpful for you.