maxmind/MaxMind-DB-Reader-php — pull request #6 by martinml (2013-12-09 17:43:31+00:00)
Title: Cache I/O when doing several IP searches in the same instance

I store the `mmdb` database in a remote filesystem, which has slow random I/O. When profiling with `xhprof` I found that the hotspot for my use case was the native `fread()` and `fseek()` calls (90%+ of the time), so I made a little hack to optimize it a bit and avoid a few duplicated reads when doing several seeks in the same run (i.e. instantiate once, seek multiple times).

For that use case (500 random IP queries) I measured the following maximum queries per second after several runs:
- base: 10 QPS (~500 KB used)
- ftell: 25 QPS (~500 KB used)
- inner cache: 40 QPS (~2600 KB used)
- inner cache + ftell: 85 QPS (~2600 KB used)

Measured with PHP 5.3.3-7+squeeze17 with Suhosin in Debian 6.