Jekyll2023-11-09T02:18:26+00:00https://github.com/mathmania/feed.xmlGlidkHi! I'm Mathieu Lambert, currently a Software developer at Ticketmaster and this is my blog.Mathieu LambertCan a pocket router go fast? (GL-AR750)2021-12-22T00:00:00+00:002021-12-22T00:00:00+00:00https://github.com/mathmania/2021/12/22/Benchmarking-crappy-router<p>With a <a href="https://www.gl-inet.com/products/gl-ar750/">GL-AR750</a> I had laying around, I wondered what fun project I could do with it. I then figured that with a USB 2.0 port AND a micro-sd card this could be a small NAS to duplicate some backup!</p>
<p>This could be the perfect device for an off-site backup. Even if I already knew that it would not be blazing fast, I wondered what kind of performance this small package could handle!</p>
<p>The specification of this small little router look like :</p>
<ul>
<li>A small linux OS (openWRT)</li>
<li>650 Mhz single core processor (QCA9531)</li>
<li>16 MB of flash storage!</li>
<li>128 MB of DDR2 Ram</li>
<li>802.11a/b/g/n/ac</li>
<li>3 Ethernet ports</li>
<li>One Micro usb port</li>
<li>one USB 2.0 port</li>
</ul>
<p>Yes, Quite the little device!</p>
<p>I began by benchmarking an SD card to know what performance it could reach without being limited by the Micro Usb port of the AR750. I obtained something like :</p>
<p><img src="/assets/img/original_stats.png" alt="the base benchmark of the sd card" /></p>
<p>So about 22 MB/s read speed and 14 MB/s write speed.</p>
<p>Before testing the sd card, I ran a quick Iperf3 benchmark just to make sure that the device could handle a synthetic load on its network interface.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mathieu@LINUXPUTER:~$ iperf3 -c 192.168.0.89 -f K
Connecting to host 192.168.0.89, port 5201
[ 5] local 192.168.0.31 port 48898 connected to 192.168.0.89 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 12.6 MBytes 12877 KBytes/sec 0 471 KBytes
[ 5] 1.00-2.00 sec 11.5 MBytes 11736 KBytes/sec 0 471 KBytes
[ 5] 2.00-3.00 sec 11.4 MBytes 11675 KBytes/sec 0 471 KBytes
[ 5] 3.00-4.00 sec 11.4 MBytes 11674 KBytes/sec 0 471 KBytes
[ 5] 4.00-5.00 sec 10.5 MBytes 10702 KBytes/sec 0 471 KBytes
[ 5] 5.00-6.00 sec 11.4 MBytes 11674 KBytes/sec 0 471 KBytes
[ 5] 6.00-7.00 sec 11.4 MBytes 11675 KBytes/sec 0 471 KBytes
[ 5] 7.00-8.00 sec 10.5 MBytes 10701 KBytes/sec 0 471 KBytes
[ 5] 8.00-9.00 sec 11.4 MBytes 11675 KBytes/sec 0 471 KBytes
[ 5] 9.00-10.00 sec 11.4 MBytes 11674 KBytes/sec 0 471 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 113 MBytes 11606 KBytes/sec 0 sender
[ 5] 0.00-10.04 sec 111 MBytes 11364 KBytes/sec receiver
iperf Done.
</code></pre></div></div>
<p>That seems good, I was using the 100 mbits ethernet port so this was also expected to cap around this speed. While running the Iperf3 benchmark the cpu was pinned at 100% … so yeah I wasn’t expecting to reach that kind of speed with the sd card.</p>
<h2 id="first-try--scp">First try : scp</h2>
<p>I began by running the most basic scp command to get a first impression on what kind of performance I would get :</p>
<p>For the writing speed I did :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>scp -v linuxmint-20.2-mate-64bit.iso root@192.168.0.89:/mnt/sda1/download/
...
linuxmint-20.2-mate-64bit.iso 2% 56MB 4.4MB/s 07:34 ETA
</code></pre></div></div>
<p>For the reading speed test I did the inverse command and got :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>scp -v root@192.168.0.89:/mnt/sda1/download/linuxmint-20.2-mate-64bit.iso ./testiso.iso
...
linuxmint-20.2-mate-64bit.iso 2% 60MB 5.0MB/s 06:37 ETA
</code></pre></div></div>
<p><img src="/assets/img/scp_htop.png" alt="The htop view while running SCP" /></p>
<p>The thing I noticed for both these tests was how the dropbear was using most of the cpu instead of the scp command. I also wondered why the read speed was hitting a ceiling at 5.0Mb/s.</p>
<p>I assumed that high cpu usage of the dropbear process was because of the encryption and wondered if I could get something a little bit faster by having a quicker SSH encryption. Sadly openWRT doesn’t contain much cypher so I didn’t get better results.I then wondered if using an other program could yield me quicker results.</p>
<h2 id="second-try--rsync">Second try : rsync</h2>
<p>I then wondered if I could gain any speed by just using rsync instead of scp. I changed my basic scp function for the equivalent basic rsync function :</p>
<p>For the writing speed I got :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$rsync --progress linuxmint-20.2-mate-64bit.iso root@192.168.0.89:/mnt/sda1/download/rsynctest.iso
sending incremental file list
linuxmint-20.2-mate-64bit.iso
221,904,896 10% 3.26MB/s 0:09:35
</code></pre></div></div>
<p>And for the reading speed I got :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$rsync --progress root@192.168.0.91:/mnt/sda1/download/linuxmint-20.2-mate-64bit.iso ./testfile.iso
linuxmint-20.2-mate-64bit.iso
336,035,840 15% 3.74MB/s 0:07:52
</code></pre></div></div>
<p><img src="/assets/img/rsync_htop.png" alt="The htop view while running rsync this time" /></p>
<p>This was actually quite underwhelming in term of speed. I was expecting at least the same speed as SCP and maybe a slight advantage, but I did not expect a downgrade in performance. Fortunately, the time spent researching information on rsync made me stumble onto something really interesting. Rsync has a tcp protocol to talk from an Rsync client to a <a href="https://linux.die.net/man/5/rsyncd.conf">Rsync daemon</a>.</p>
<h2 id="third-try--the-rsync-protocol">Third try : The rsync protocol</h2>
<p>On the server I installed the rsync daemon using the openWRT package manager. I then modified the <code class="language-plaintext highlighter-rouge">/etc/rsyncd.conf</code>file so that it contained :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code> /etc/rsyncd.conf
# Minimal configuration for rsync daemon
# Next line required for init script
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
# Basic shared folder
[test_dir]
path = /mnt/sda1/download
read only = false
</code></pre></div></div>
<p>An rsync client can then access the <strong>test_dir</strong> folder and read/write to it.
On the client I then ran similar command as before, but this time using the <code class="language-plaintext highlighter-rouge">rsync://</code> protocol :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$rsync --progress rsync://192.168.2.42:/test_dir/linuxmint-20.2-mate-64bit.iso ./testiso.iso
linuxmint-20.2-mate-64bit.iso
667,385,856 31% 6.08MB/s 0:03:56
</code></pre></div></div>
<p>Success!! This time I nearly doubled my previous download speed! The thing to know is that by default this protocol isn’t really secure so you need to add a password to your network share.</p>
<p>The biggest win of all is that the cpu on our small server wasn’t even capped at 100% so there must be another bottleneck now!.</p>
<p><img src="/assets/img/rsync_protocol.png" alt="htop of the transfer when using the rsync protocol" /></p>
<p>Just for fun I tested the write speed onto our little server and the speed was more than decent… and I actually really don’t understand how this could be possible.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rsync --progress ./linuxmint-20.2-cinnamon-64bit.iso rsync://192.168.2.42:/test_dir/write_iso.iso
linuxmint-20.2-cinnamon-64bit.iso
213,155,840 9% 9.16MB/s 0:03:27
</code></pre></div></div>
<p>We were almost reaching the maximum write speed of our SD card, and we were faster than the reading speed which doesn’t really make sense…
I’ll have to dig a little deeper to explain why. The good news is that those speeds were far better than what we initially had, so I consider this a win!</p>
<p>The key takeaway message is that on a small embedded device, there is <strong>a good performance boost that can be gained by bypassing the ssh protocol</strong>. Just don’t forget to secure your network share if you end up using the rsync daemon!</p>Mathieu LambertWith a GL-AR750 I had laying around, I wondered what fun project I could do with it. I then figured that with a USB 2.0 port AND a micro-sd card this could be a small NAS to duplicate some backup!Configuring dynamic DNS for namecheap using DDClient on fedora2020-11-30T00:00:00+00:002020-11-30T00:00:00+00:00https://github.com/mathmania/2020/11/30/ddclient-namecheap-fedora31<p>I was recently trying to configure a dynamic DNS to host a server at home, but wanted it to be reliable and simple.</p>
<p>I found that namecheap provide multiple ways to configure a dynamic DNS, and even include a small executable that you can install to do this automatically. The thing is my server is running Fedora, not Windows. After searching on the namecheap website I found <a href="https://www.namecheap.com/support/knowledgebase/article.aspx/583/11/how-do-i-configure-ddclient">this article</a> that explains how to setup dynamic DNS using <a href="https://github.com/ddclient/ddclient">DDClient</a>.</p>
<p>Note : This tutorial is targeted at <strong>Fedora 31</strong> , but should be compatible newer versions.</p>
<p><strong>1.</strong> First install DDClient :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo dnf install ddclient
</code></pre></div></div>
<p><strong>2.</strong> After DDClient is installed, we now need to generate a one time password on the namecheap website.
In the domain list, navigate to <strong>manage</strong> -> <strong>Advanced Dns</strong> and toggle the dynamic dns option. This will generate a random password that will be used with DDClient.</p>
<p>You can then specify an <strong>A+Dynamic DNS Record</strong> (instead of the classic A Record)<br />
<img src="/assets/img/a_dynamic.png" alt="The dynamic dns + A record" /></p>
<p>After edit <code class="language-plaintext highlighter-rouge">/etc/ddclient.conf</code> to add :</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>protocol=namecheap
use=web, web=dynamicdns.park-your-domain.com/getip
server=dynamicdns.park-your-domain.com
login=<your domain name without the www>
password=<password generated>
<subdomain>
</code></pre></div></div>
<p>Replace subdomain with the the one specified in the <strong>Host</strong> value of your <strong>A+Dynamic DNS Record</strong>.</p>
<p>You can test the config file by running the following command. You should see at the end of the logfile <strong>SUCCESS: <subdomain you specified></strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo ddclient -daemon=0 -debug -verbose -noquiet
</code></pre></div></div>
<p><strong>3.</strong> Finally we’ll create a systemd service to make sure our program keep running. Create a file in <code class="language-plaintext highlighter-rouge">/etc/systemd/system/ddclient.service</code> that contains the following content:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#/usr/lib/systemd/system/ddclient.service
[Unit]
Description=ddclient Service
After=network.target
[Service]
Type=forking
PIDFile=/var/run/ddclient.pid
ExecStart=/usr/sbin/ddclient -pid /var/run/ddclient.pid -file /etc/ddclient.conf -daemon 300
ExecStop=/usr/bin/pkill -SIGKILL -P /var/run/ddclient.pid
</code></pre></div></div>
<p>We now need to register this service by running <code class="language-plaintext highlighter-rouge">sudo systemctl enable ddclient.service</code>.
And finally we run the new service with <code class="language-plaintext highlighter-rouge">sudo systemctl start ddclient.service</code></p>
<p>The value of the <strong>A+Dynamic DNS Record</strong> in the namecheap interface should now be updated with your current IP address!</p>Mathieu LambertI was recently trying to configure a dynamic DNS to host a server at home, but wanted it to be reliable and simple.