Linux

PHP Benchmark Maxmind Geolite2 vs IP2Location

This article is about simple benchmark Maxmind Geolite2 IP DB vs IP2Location IP DB.

When we want to detect visitor city or country by IP, we can use free version of Maxmind Geolite2 IP DB and IP2Location Lite.

The benchmark use server with specification:

  • CPU: Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz 6 Cores 12 Threads
  • Memory: 256 Gb
  • HDD: SSD Datacenter / Enterprise
  • PHP: 7.4 with Zend-Opcache (and APCU for testing cached IP address)

On this benchmark, we use GeoLite2 Free from Maxmind.

And for IP2Location Lite IP DB we can download on https://lite.ip2location.com/

Maxmind Geolite2 vs IP2Location

PHP Code is for testing Maxmind City IP DB:

<?php
require 'vendor/autoload.php';

use MaxMind\Db\Reader;

srand(0);

$reader = new Reader('ip2location/GeoLite2-City/GeoLite2-City.mmdb');
$count = 50000;
$startTime = microtime(true);
for ($i = 0; $i < $count; ++$i) {
    $ip = long2ip(rand(0, pow(2, 32) - 1));
    $t = $reader->get($ip);
    if ($i % 1000 === 0) {
        echo $i . ' ' . $ip . "\n";
    }
}
$endTime = microtime(true);

$duration = $endTime - $startTime;
echo 'Maxmind Requests per second: ' . $count / $duration . "\n\n";

PHP Code is for testing IP2Location City IP DB:

<?php
require 'vendor/autoload.php';
srand(0);

$db = new \IP2Location\Database('ip2location/IP2LOCATION-LITE-DB11.BIN', \IP2Location\Database::MEMORY_CACHE);
$count = 50000;
$startTime = microtime(true);
for ($i = 0; $i < $count; ++$i) {
    $ip = long2ip(rand(0, pow(2, 32) - 1));
    $t = $db->lookup($ip, \IP2Location\Database::ALL);
    if ($i % 1000 === 0) {
        echo $i . ' ' . $ip . "\n";
    }
}
$endTime = microtime(true);
$duration = $endTime - $startTime;
echo 'IP2Location Requests per second: ' . $count / $duration . "\n\n";

PHP Benchmark Maxmind Geolite2 IP DB vs IP2Location Lite City IP DB

PHP Benchmark Maxmind City IP DB

php maxmind_benchmark.php
0 140.127.10.172
……..
……..
49000 179.42.132.101
Maxmind Requests per second: 1883.8705388764
PHP Benchmark Maxmind IP DB Request Per Seconds

PHP Benchmark IP2Location Lite City IP DB using Memory Cache

php ip2location_benchmark.php
0 140.127.10.172
..............
..............
49000 179.42.132.101
IP2Location Requests per second: 46120.993185496
PHP Benchmark IP2Location IP DB Request Per Seconds

On this benchmark, IP2Location clearly win in Requests Per Second, Maxmind got speed 1883 Requests Per Second and IP2Location got 46.120 Requests Per Second.

IP2Location City IP DB was 2.449% faster than Maxmind City IP DB.

IP2Location can use MEMORY_CACHE for City DB IP File.

Related Post

PHP Benchmark IP2Location Lite City IP DB using File IO (Disk)

Let’s see if IP2Location City IP DB File on Disk (SSD).

<?php
require 'vendor/autoload.php';
srand(0);

$db = new \IP2Location\Database('ip2location/IP2LOCATION-LITE-DB11.BIN', \IP2Location\Database::FILE_IO);
$count = 50000;
$startTime = microtime(true);
for ($i = 0; $i < $count; ++$i) {
    $ip = long2ip(rand(0, pow(2, 32) - 1));
    $t = $db->lookup($ip, \IP2Location\Database::ALL);
    if ($i % 1000 === 0) {
        echo $i . ' ' . $ip . "\n";
    }
}
$endTime = microtime(true);
$duration = $endTime - $startTime;
echo 'IP2Location Requests per second: ' . $count / $duration . "\n\n";

The result if we use IP2Location IP DB File IO is:

php ip2location_benchmark.php
0 140.127.10.172
.............
.............
49000 179.42.132.101
IP2Location Requests per second: 16747.449752708
PHP Benchmark IP2Location IP DB Request Per Seconds Using File IO

When we use Hardisk File IO for IP2Location City IP DB speed decreased about 300% compared to Memory Cache IP2Location IP DB, we got 16.747 Requests Per Second.

It’s 889% faster than Maxmind City IP DB.

Bonus: Cache Result IP using APCU to Speed Up more than 1400%

The key of PHP Performance is Cache It, even we use for 1 or 2 seconds.

Because we will use APCU cache, we need single IP address, first we need to clear CPU cache.

When APCU Cahe is empty, we need to execute on IP2Location IP DB for first time, second request will be handled by APCU Memory.

Below is code for benchmark:

<?php
require 'vendor/autoload.php';
$ip = '94.130.248.205';
$cache_key = 'IP_DB_'.$ip;
//apcu_delete($cache_key);

srand(0);
$count = 50000;
$startTime = microtime(true);
if(apcu_exists($cache_key)===false) {
 $db = new \IP2Location\Database('ip2location/IP2LOCATION-LITE-DB11.BIN', \IP2Location\Database::MEMORY_CACHE);
 $t = $db->lookup($ip, \IP2Location\Database::ALL);
 apcu_store($cache_key, serialize($t), 300);
}
for ($i = 0; $i < $count; ++$i) {
 $t = unserialize(apcu_fetch($cache_key));
    if ($i % 1000 === 0) {
        echo $i . ' ' . $ip . "\n";
    }
}
$endTime = microtime(true);
$duration = $endTime - $startTime;
echo 'APCU Memory Requests per second: ' . $count / $duration . "\n\n";

The result is

php ip2location_benchmark.php
0 94.130.248.205
..............
..............
49000 94.130.248.205
APCU Memory Requests per second: 718648.20316703
PHP Benchmark IP2Location IP DB Request Per Seconds Using APCU

If we use APCU Memory, Request per second is 718.648.

View Comments

  • Hm.
    So what you're basically doing is download the database for each of the services, and then, using the provided PHP SDK for each of them, try to run a benchmark of sheer speed in running whatever complex code each has provided.
    Since we cannot compare the actual SDK code directly (you've not posted it here), we can only assume, from the benchmark, that MaxMind has not so talented PHP programmers than IP2Location. That doesn't say much: after all, you can simply extract the content database fields in each case, import them all into a super-fast KV datastore, and just do lookups over it. Since, in theory, both databases have the same data (IP -> (Country; City)), the results would be exactly the same.
    So it's 'wrong' to claim that IP2Location is 'slower' than MaxMind; that's just the case if you're comparing each of their SDKs. Try using MaxMind's data with the IP2Location SDK (by converting the format), and there should be no difference whatsoever.
    No, the real difference will be in the accuracy of the data (and how can you measure that?), as well as in the amount of data provided for free by each company. Imagine that IP2Location has 1000 times more information on their free database than MaxMind's. Sure, their SDK may be terrible; but it would potentially be far more accurate! That would be a good tradeoff for some uses...
    Sorry, but I'm not convinced that you're measuring anything worthwhile — except judging how well the programmers of each company are familiar with PHP and how good their code is. That's pretty much irrelevant for the end-user who wants to use their free data and incorporate it in their own system...

    • Thank you. Based on test above, very clear that IP2Location Faster than Maxmind.

      IP2Location City IP DB was 2449% faster than Maxmind City IP DB on MEMORY_CACHE.
      IP2Location 889% faster than Maxmind City IP DB on File IO.

      There is no argument "So it’s ‘wrong’ to claim that IP2Location is ‘slower’ than MaxMind;".
      So I'm confused by your comment.

      Please note that we does not compare the accuracy, but only speed on same free database.

Recent Posts

How to fix yum update error thread.error: can’t start new thread

If you found error thread.error: can't start new thread on yum update command on CentOS…

5 months ago

How to securing Cockpit login with Google Two Factor Authenticator 2FA

Cockpit is a web-based graphical interface for servers, intended for everyone, especially those who are:…

8 months ago

How to install Cockpit on CentOS 7 / CentOS 9 Stream and configure Nginx reserve proxy

From cockpit-project.org, Cockpit is a web-based graphical interface for servers, intended for everyone, especially those…

10 months ago

How to install and configure Nginx with HTTP3 on CentOS 9 Stream / RHEL 9

We have been using Nginx with HTTP3 for more than 1 year on our production…

11 months ago

How to sync date time using Crony on CentOS 9 Stream / RHEL 9

On CentOS 7, to sync date time we often use NTPD. But on CentOS 9,…

11 months ago

How to install and enable REMI repository on CentOS 9 Stream

Remi repository is one of third-party repository that have latest update of PHP on Enterprise…

11 months ago