-
-
Save aminer/f249ec206af6513aa8a69d143122ad86 to your computer and use it in GitHub Desktop.
PHP7 vs. PHP5 benchmark resources (Aerospike config file and scripts for Aerospike PHP Client version 3.4.10 based on PHP5 and PHP7)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Aerospike database configuration file. | |
service { | |
user root | |
group root | |
run-as-daemon | |
pidfile /var/run/aerospike/asd.pid | |
transaction-queues 32 | |
transaction-threads-per-queue 4 | |
service-threads 32 | |
proto-fd-max 15000 | |
} | |
logging { | |
file /var/log/aerospike/aerospike.log { | |
context any info | |
} | |
} | |
network { | |
service { | |
address any | |
port 3000 | |
} | |
heartbeat { | |
mode mesh | |
port 3002 | |
interval 250 | |
timeout 10 | |
} | |
fabric { | |
port 3001 | |
} | |
info { | |
port 3003 | |
} | |
} | |
namespace test { | |
memory-size 15G | |
default-ttl 0 | |
storage-engine memory | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
################################################################################ | |
# Copyright 2013-2016 Aerospike, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
################################################################################ | |
function rutime($ru, $rus, $index) { | |
return ($ru["ru_$index.tv_sec"] * 1000 + intval($ru["ru_$index.tv_usec"] / 1000)) | |
- ($rus["ru_$index.tv_sec"] * 1000 + intval($rus["ru_$index.tv_usec"] / 1000)); | |
} | |
class Employee | |
{ | |
public $desg = 'Manager'; | |
} | |
function parse_args() { | |
$shortopts = ""; | |
$shortopts .= "h::"; /* Optional host */ | |
$shortopts .= "p::"; /* Optional port */ | |
$shortopts .= "w::"; /* Optionally write every Nth operation */ | |
$shortopts .= "n::"; /* Optionally number of read-write operations */ | |
$longopts = array( | |
"host::", /* Optional host */ | |
"port::", /* Optional port */ | |
"write-every::", /* Optionally write every Nth operation */ | |
"num-ops::", /* Optionally number of read-write operations */ | |
"help", /* Usage */ | |
); | |
global $argv; | |
$options = getopt($shortopts, $longopts); | |
for ($i = 0; $i <= count($options); $i++) { | |
array_shift($argv); | |
} | |
$options['_args'] = $argv; | |
return $options; | |
} | |
$args = parse_args(); | |
if (isset($args["help"])) { | |
echo "php rw-worker.php [-hHOST] [-pPORT] [-wWRITE EVERY Nth RECORD] [-nRECORDS] LOGFILE\n"; | |
echo " or\n"; | |
echo "php rw-worker.php [--host=HOST] [--port=PORT] [--write-every=WRITE EVERY Nth RECORD] [--num-ops=RECORDS] LOGFILE\n"; | |
exit(1); | |
} | |
$addr = (isset($args["h"])) ? (string) $args["h"] : ((isset($args["host"])) ? (string) $args["host"] : "localhost"); | |
$port = (isset($args["p"])) ? (integer) $args["p"] : ((isset($args["port"])) ? (string) $args["port"] : 3000); | |
$total_ops = (isset($args["n"])) ? (integer) $args["n"] : ((isset($args["num-ops"])) ? (string) $args["num-ops"] : 100000); | |
$write_every = (isset($args["w"])) ? (integer) $args["w"] : ((isset($args["write-every"])) ? (string) $args["write-every"] : 10); | |
$log = $args["_args"][0]; | |
$pid = getmypid(); | |
echo "rw-worker.php launched with process ID $pid\n"; | |
$config = array("hosts" => array(array("addr" => $addr, "port" => $port))); | |
$db = new Aerospike($config, false); | |
if (!$db->isConnected()) { | |
file_put_contents($log, "$pid|0|0|0|0|0|0|0\n", FILE_APPEND); | |
exit(1); | |
} | |
$key = $db->initKey("test", "rw-performance", $pid); | |
$writes = 0; | |
$write_fails = 0; | |
$reads = 0; | |
$read_fails = 0; | |
$begin = getrusage(); | |
$initial_mem = memory_get_usage(false); | |
$obj1 = new Employee(); | |
$obj2 = new Employee(); | |
$obj3 = new Employee(); | |
$map = array("k1"=>$obj1, "k2"=>$obj2, "k3"=>$obj3, "k4"=>7, "k5"=>8, "k6"=>8, "k7"=>array("k1"=>10, "k2"=>5, "k3"=>6, "k4"=>7, "k5"=>8, "k6"=>8)); | |
$softskills = array("speaking", "reading", "writing"); | |
$skills = array("python", "c", "java", $softskills); | |
$innermostmap = array("month"=>"May", "year"=>2013); | |
$innermap = array("degree"=>$innermostmap, "aggregate"=>70); | |
$mymap = array("name"=>"aero", "age"=>23, "edu"=>$innermap, "skills"=>$skills); | |
$innermostlist = array("twitter", 100, TRUE); | |
$innerlist = array(1, 2, "facebook", $innermostlist); | |
$mylist = array(10, 20, $obj1, $obj2, $obj3, "whatsup", $innerlist, $mymap, $map); | |
$map1 = array("k1", TRUE, 56=>$softskills); | |
$map2 = array("k2", $obj1, $obj2, TRUE, 100, $obj3); | |
$rec = array("bin1"=>$map1, "bin2"=>$map1, "bin3"=>$map1, "bin4"=>$map1, "bin5"=>$map1, | |
"bin6"=>$mylist, "bin7"=>$mylist, "bin8"=>$mylist, "bin9"=>$mylist, "bin10"=>$mylist, | |
"bin11"=>$map2, "bin12"=>$map2, "bin13"=>$map2, "bin14"=>$map2, "bin15"=>$map2, | |
"bin16"=>$mylist, "bin17"=>$mylist, "bin18"=>$mylist, "bin19"=>$mylist, "bin20"=>$mylist); | |
$res = $db->put($key, $rec); | |
if ($res !== Aerospike::OK) { | |
$end = getrusage(); | |
$delta = rutime($end, $begin, "utime") / 1000; | |
$tps = (1 / $delta); | |
file_put_contents($log, "$pid|1|$delta|$tps|0|0|1|1\n", FILE_APPEND); | |
exit(2); | |
} | |
$writes++; | |
for ($num_ops = 1; $num_ops < $total_ops; $num_ops++) { | |
$new_key = "key{$num_ops}"; | |
$$new_key = $db->initKey("test", "performance", $num_ops); | |
if (($num_ops % $write_every) == 0) { | |
$res = $db->put($$new_key, $rec); | |
$writes++; | |
if ($res !== Aerospike::OK) { | |
$write_fails++; | |
} | |
} else { | |
$res = $db->get($$new_key, $r); | |
$reads++; | |
if ($res !== Aerospike::OK) { | |
$read_fails++; | |
} | |
} | |
} | |
$final_mem = memory_get_peak_usage(false); | |
$mem_used = (($final_mem - $initial_mem) / 1024) / 1024 . " MB"; | |
$end = getrusage(); | |
$delta = rutime($end, $begin, "utime") / 1000; | |
echo "Process " . $pid . " used " . $mem_used . " of memory and " . $delta . " sec for its computations - "; | |
echo "it spent " . rutime($end, $begin, "stime") / 1000 . " sec in system calls\n"; | |
$tps = ($num_ops / $delta); | |
file_put_contents($log, "$pid|$num_ops|$delta|$tps|$reads|$read_fails|$writes|$write_fails\n", FILE_APPEND); | |
$db->close(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
################################################################################ | |
# Copyright 2013-2016 Aerospike, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
################################################################################ | |
function rutime($ru, $rus, $index) { | |
return ($ru["ru_$index.tv_sec"] * 1000 + intval($ru["ru_$index.tv_usec"] / 1000)) | |
- ($rus["ru_$index.tv_sec"] * 1000 + intval($rus["ru_$index.tv_usec"] / 1000)); | |
} | |
class Employee | |
{ | |
public $desg = 'Manager'; | |
} | |
function parse_args() { | |
$shortopts = ""; | |
$shortopts .= "h::"; /* Optional host */ | |
$shortopts .= "p::"; /* Optional port */ | |
$shortopts .= "w::"; /* Optionally write every Nth operation */ | |
$shortopts .= "n::"; /* Optionally number of read-write operations */ | |
$longopts = array( | |
"host::", /* Optional host */ | |
"port::", /* Optional port */ | |
"write-every::", /* Optionally write every Nth operation */ | |
"num-ops::", /* Optionally number of read-write operations */ | |
"help", /* Usage */ | |
); | |
global $argv; | |
$options = getopt($shortopts, $longopts); | |
for ($i = 0; $i <= count($options); $i++) { | |
array_shift($argv); | |
} | |
$options['_args'] = $argv; | |
return $options; | |
} | |
$args = parse_args(); | |
if (isset($args["help"])) { | |
echo "php rw-worker.php [-hHOST] [-pPORT] [-wWRITE EVERY Nth RECORD] [-nRECORDS] LOGFILE\n"; | |
echo " or\n"; | |
echo "php rw-worker.php [--host=HOST] [--port=PORT] [--write-every=WRITE EVERY Nth RECORD] [--num-ops=RECORDS] LOGFILE\n"; | |
exit(1); | |
} | |
$addr = (isset($args["h"])) ? (string) $args["h"] : ((isset($args["host"])) ? (string) $args["host"] : "localhost"); | |
$port = (isset($args["p"])) ? (integer) $args["p"] : ((isset($args["port"])) ? (string) $args["port"] : 3000); | |
$total_ops = (isset($args["n"])) ? (integer) $args["n"] : ((isset($args["num-ops"])) ? (string) $args["num-ops"] : 100000); | |
$write_every = (isset($args["w"])) ? (integer) $args["w"] : ((isset($args["write-every"])) ? (string) $args["write-every"] : 10); | |
$log = $args["_args"][0]; | |
$pid = getmypid(); | |
echo "rw-worker.php launched with process ID $pid\n"; | |
$config = array("hosts" => array(array("addr" => $addr, "port" => $port))); | |
$db = new Aerospike($config, false); | |
if (!$db->isConnected()) { | |
file_put_contents($log, "$pid|0|0|0|0|0|0|0\n", FILE_APPEND); | |
exit(1); | |
} | |
$key = $db->initKey("test", "rw-performance", $pid); | |
$writes = 0; | |
$write_fails = 0; | |
$reads = 0; | |
$read_fails = 0; | |
$begin = getrusage(); | |
$obj1 = new Employee(); | |
$obj2 = new Employee(); | |
$obj3 = new Employee(); | |
$map = array("k1"=>$obj1, "k2"=>$obj2, "k3"=>$obj3, "k4"=>7, "k5"=>8, "k6"=>8, "k7"=>array("k1"=>10, "k2"=>5, "k3"=>6, "k4"=>7, "k5"=>8, "k6"=>8)); | |
$softskills = array("speaking", "reading", "writing"); | |
$skills = array("python", "c", "java", $softskills); | |
$innermostmap = array("month"=>"May", "year"=>2013); | |
$innermap = array("degree"=>$innermostmap, "aggregate"=>70); | |
$mymap = array("name"=>"aero", "age"=>23, "edu"=>$innermap, "skills"=>$skills); | |
$innermostlist = array("twitter", 100, TRUE); | |
$innerlist = array(1, 2, "facebook", $innermostlist); | |
$mylist = array(10, 20, $obj1, $obj2, $obj3, "whatsup", $innerlist, $mymap, $map); | |
$map1 = array("k1", TRUE, 56=>$softskills); | |
$map2 = array("k2", $obj1, $obj2, TRUE, 100, $obj3); | |
$rec = array("bin1"=>$map1, "bin2"=>$map1, "bin3"=>$map1, "bin4"=>$map1, "bin5"=>$map1, | |
"bin6"=>$mylist, "bin7"=>$mylist, "bin8"=>$mylist, "bin9"=>$mylist, "bin10"=>$mylist, | |
"bin11"=>$map2, "bin12"=>$map2, "bin13"=>$map2, "bin14"=>$map2, "bin15"=>$map2, | |
"bin16"=>$mylist, "bin17"=>$mylist, "bin18"=>$mylist, "bin19"=>$mylist, "bin20"=>$mylist); | |
$res = $db->put($key, $rec); | |
if ($res !== Aerospike::OK) { | |
$end = getrusage(); | |
$delta = rutime($end, $begin, "utime") / 1000; | |
$tps = (1 / $delta); | |
file_put_contents($log, "$pid|1|$delta|$tps|0|0|1|1\n", FILE_APPEND); | |
exit(2); | |
} | |
$writes++; | |
for ($num_ops = 1; $num_ops < $total_ops; $num_ops++) { | |
if (($num_ops % $write_every) == 0) { | |
$res = $db->put($key, $rec); | |
$writes++; | |
if ($res !== Aerospike::OK) { | |
$write_fails++; | |
} | |
} else { | |
$res = $db->get($key, $r); | |
$reads++; | |
if ($res !== Aerospike::OK) { | |
$read_fails++; | |
} | |
} | |
} | |
$end = getrusage(); | |
$delta = rutime($end, $begin, "utime") / 1000; | |
echo "Process " . $pid . " used " . $delta . " sec for its computations - "; | |
echo "it spent " . rutime($end, $begin, "stime") / 1000 . " sec in system calls\n"; | |
$tps = ($num_ops / $delta); | |
file_put_contents($log, "$pid|$num_ops|$delta|$tps|$reads|$read_fails|$writes|$write_fails\n", FILE_APPEND); | |
$db->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aerospike.conf
is the server-side configuration file used on the aerospike cluster node.rw-worker.php
is the multi-process script used for benchmarking the Aerospike PHP Client based on PHP7 and PHP5.rw-worker-mem-usage.php
is the multi-process script used for measuring memory usage, where we create a new key variable per iteration. For example, in iteration 6, we usekey6
to initialize a new$key6
. This will increase the memory usage per iteration.Usage
./rw-concurrent.sh -h 192.168.119.3 -c 4 -n 100000 -w 2 run.log ## 50:50 Reads/Writes
./rw-concurrent.sh -h 192.168.119.3 -c 4 -n 100000 -w 10000 run.log ## Full reads
./rw-concurrent.sh -h 192.168.119.3 -c 4 -n 100000 -w 1 run.log ## Full writes