I just got my Rock Pi 4B… I had to have a friend bring it to me from China. Mother of god, I am IMPRESSED!! So look… I set up Ubuntu 18.01, PHP7.2 and Mysql 5.7 (I couldn’t get MySQL 8.0 set up on it). I skipped using the SD card (although I discovered you have an SD card in the Rock to make it use the M.2) and am instead using the Kingston KC1000 480GB M.2 SSD. It doesn’t disappoint!!
I ran a PHP script that randomizes data and inserts it into the localhost MySQL database. I ran these tests with the exact same script against my current 4 core, 8GB Digital Ocean droplet with PHP 7.2 and MySQL 8.0, and an identical droplet from Linode. I populated 200,001 rows and then another 200,001 rows of indexed data. THese plans cost me $40 per month, each. The Rock Pi was $75 USD, and I got the SSD for free.
The first think you are going to ask is "Did the Rock Pi outperform the the droplets? In short, the answer is: It was an epic battle! Absolutely incredible! I will post the scripts for PHP and MySql at the end so you can try it out yourself with your own setup, but let’s look at the numbers:
Writing:
Rock Pi Server:
Step 1:
Time to insert 200001 records: 368.8964
Average time per record = 0.0018444727776361
Step 2:
Time to insert 200001 records: 387.2555
Average time per record = 0.0019362678186609
Linode Server:
Step 1:
Time to insert 200001 records: 211.4915
Average time per record = 0.0010574522127389
Step 2:
Time to insert 200001 records: 184.0102
Average time per record = 0.000920046399768
Digital Ocean:
Step 1:
Time to insert 200001 records: 271.2323
Average time per record = 0.0013574522127389
Step 2:
Time to insert 200001 records: 266.9245
Average time per record = 0.0013346158399768
The Linode server was about 48% faster in writing and the Digital Ocean server was about 29% faster in writing. But NOT SO FAST! This can potentially be attributed to the fact MySql 8.0 is supposed to be up to TWICE as fast as MySQL 5.7. And if this is the case, the Rock PI might actually be faster up to 30% faster in performance! I can’t be sure, however, until I can get MySQL 8.0 running on the Rock.
Reading: SELECT Statement:
Reading is another matter altogether, and I am very happy about it.
I ran a geospatial query that is very heavy in math to determine what 1000 MAC addresses (out of the 400k) were in the closest proximity to a given point. First, it has to calculate every triangulation, discard every one not between 1 and 4 miles, and then order the first 1000. It’s a heavy-math query and the Rock crushed it! I will put the select query at the end. The results:
Linode: 1.939 seconds
Digital Ocean: 2.1217 seconds
Rock Pi: 1.688 seconds
WOW!!! It’s all I can say about that.
One thing… the Rock’s processor can get pretty darned hot. Yesterday, I loaded 88,000,000 rows of data onto it… and it was getting so hot I rested it so the processor was sitting on a silver spoon And so, I decided to do the rational thing… I fabricated a heat sink for it. Keep in mind, I will be making a server farm (one Rock PI for web requests, one Rock PI for databases and one additional Rock PI for mirroring the MySql database (in case of a failure). And so , my heat sink is big enough to be shared by all three of them. You can’t see it, but there is a chick of aluminum that joins the surface of the Rock’s processor to the face of the heat sink. Also, I used a chick of aluminum to cover the chips of the M.2 SSD to absorb some of the heat when it’s cranking away on long tasks. and it works GREAT!!!
Think about it: This little Rock pi is more potent than the 2U servers of just 5 years ago and is more potent that all but the biggest VPS’s out there. If you need data crunching on a budget, this little guy is your thing!
Here’s the PHP script I used… try it yourself on whatever hardware and see what your results are!
<?php
$database = include('Config/macs.php');
$db = mysqli_connect($database['host'], $database['user'], $database['pass'], $database['name']);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();}
$logMacs = $db->prepare("INSERT INTO Macs (Mac, AcqDate, Lat, Lon) Values (?,NOW(), ?,?)");
$logMacs->bind_param('sdd', $mac, $lat, $lon);
$msc=microtime(true);
for ($x = 0; $x <= 200000; $x++) {
$mac= implode(':', str_split(str_pad(base_convert(mt_rand(0, 0xffffff), 10, 16) . base_convert(mt_rand(0, 0xffffff), 10, 16), 12), 2));
$lat = 38.914415+(rand(-14,14)*.01); $lon = -77.015264+(rand(-30,30)*.01);
$logMacs->execute();}
$logMacs->close(); $db->close();
$msc=microtime(true)-$msc; $secs = round($msc,4); echo "Time to insert $x records: $secs <br>";
echo "Average time per record = ".$secs/$x;
The code for the Database:
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS Macs
;
CREATE TABLE Macs
(
Mac
char(17) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
AcqDate
datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
Lat
double(10, 8) NULL DEFAULT NULL,
Lon
double(11, 8) NULL DEFAULT NULL,
INDEX Mac
(Mac
) USING BTREE,
INDEX Lat
(Lat
) USING BTREE,
INDEX Lon
(Lon
) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
Select Query:
SELECT Mac, round(
(
3959 * acos(
(
(
(
cos(radians(38.914415)) * cos(
radians(Lat)
)
) * cos(
(
radians(Lon) - radians(-77.015264)
)
)
) + (
sin(radians(38.914415)) * sin(
radians(Lat)
)
)
)
)
),
1
) AS distance
FROM Macs
HAVING (distance
BETWEEN 2 and 4)
ORDER BY
3959 * acos(
(
(
(
cos(radians(38.914415)) * cos(
radians(Lat)
)
) * cos(
(
radians(Lon) - radians(-77.015264)
)
)
) + (
sin(radians(38.914415)) * sin(
radians(Lat)
)
)
)
)
LIMIT 1000