<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tiago Mateus on Medium]]></title>
        <description><![CDATA[Stories by Tiago Mateus on Medium]]></description>
        <link>https://medium.com/@tmateus?source=rss-3516b9a4353b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HeqtUeU2aehnnnQp</url>
            <title>Stories by Tiago Mateus on Medium</title>
            <link>https://medium.com/@tmateus?source=rss-3516b9a4353b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:54:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tmateus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting up a Raspberry Pi Hadoop Cluster]]></title>
            <link>https://tmateus.medium.com/setting-up-a-raspberry-pi-hadoop-cluster-7fbcc0fc19a1?source=rss-3516b9a4353b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fbcc0fc19a1</guid>
            <category><![CDATA[rasperry-pi]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[hadoop-cluster]]></category>
            <dc:creator><![CDATA[Tiago Mateus]]></dc:creator>
            <pubDate>Wed, 16 Jun 2021 09:26:56 GMT</pubDate>
            <atom:updated>2021-06-16T09:26:56.098Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a “how to” step-by-step guide to set up a Raspberry Pi Hadoop Cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXqzTkBOl7ywsxyOnP0WOQ.jpeg" /><figcaption>Raspberry Pi Hadoop Cluster</figcaption></figure><h3>Why?</h3><p>This should probably be the question you have in mind. Why do I want to build a Hadoop cluster? Here’s a few reasons:</p><ul><li>Big Data is a buzzword for nearly a decade. This article might be useful as introduction to an amazing journey on this industry.</li><li>Cluster’s hardware can be used in another projects.</li><li>You will touch on interesting topics such as: networking, ssh or security.</li><li>Pis are always fun to play!</li></ul><h3>Santa’s hardware list</h3><ul><li>3x Raspberry Pies 3B+</li><li>3x Micro SD card 32GB</li><li>3x USB type C to USB 2.0</li><li>USB charger</li><li>Ethernet Switch</li><li>4x Ethernet cables</li><li>Acrylic case</li></ul><p>Total (approximately): 180€</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8hI3rqOo03trMwIjtxbYKw.jpeg" /><figcaption>Hardware setup… Ready to start!</figcaption></figure><h3>Set up the hardware</h3><ul><li>Assemble the Pis to the acrylic case</li><li>Tape the charger and router</li><li>Connect the wires</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1_s6n0N1NNuorVqFXnn7Q.jpeg" /><figcaption>Start assembling the case</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ojNCeYnV2NkFimkfhSZisg.jpeg" /><figcaption>Assembling the Pis to the case</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0NeZR5RCziVeFZDO9_xFZQ.jpeg" /><figcaption>Assemble completed</figcaption></figure><h3>Flash OS image onto SD cards</h3><ul><li>Download an Operation System (OS) for our Pis. For this guide, we are going to use the <a href="https://www.raspberrypi.org/software/operating-systems/">Raspbian</a> which is the official Raspberry Pi OS.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/156/1*wrvUx2kJaNSMq7AXhJo1FQ.png" /><figcaption>Raspbian logo</figcaption></figure><ul><li>The next step is to write the OS into our SD card. For this, we are going to use the Win32 Disk imager and the process is pretty simple: insert the SD card in our machine, open the Win32, select the iso file that we want to flash and click on write option.</li><li>Repeat this process for the remaining 2 SD cards using the same OS image.</li></ul><h3>🔓Enable SSH connection</h3><p>As of the November 2016 release, Raspberry Pi OS has the SSH server disabled by default. Due to this, we need to manually enable it.</p><ul><li>Launch Raspberry Pi Configuration from the Preferences menu</li><li>Navigate to the Interfaces tab</li><li>Select Enabled next to SSH</li><li>Click OK</li></ul><h3>Identify our Pies in the network</h3><ul><li>Connect the Pi to the switch and the power source.</li><li>To identify the Pi’s IP address, type ping raspberry.local in our terminal.</li><li>Type ssh pi@{ip}. Type yes when asked if you want to continue to connect.</li><li>We will need to type the password. By default it’s raspberry.</li></ul><p>Might be useful to keep the SSH credential in the ~/.ssh/config of our machine</p><pre>Host pi.master<br>HostName 192.168.1.115<br>User pi</pre><pre>Host pi.node1<br>HostName 192.168.1.116<br>User pi</pre><pre>Host pi.node2<br>HostName 192.168.1.117<br>User pi</pre><p>(You will have different IP addresses)</p><h3>Expand the file system</h3><p>(this needs to be done manually on each Pi)</p><p>After the SSH connection:</p><ul><li>Type sudo raspi-config to open the Configuration Tool.</li><li>Navigate to 7 Advanced Options</li><li>Select A1 Expand Filesystem and click on Finish.</li><li>Reboot the Pi typing:sudo shutdown -r now.</li></ul><h3>Hostnames</h3><p>By default, all of the Pis are known as raspberry and have a single user, the pi. Since we are creating a cluster, this might be a nightmare to manage in a future… So let’s simplify! We will assign a hostname based on its position.</p><ul><li>1º Pi is the pi.master ;</li><li>2º Pi is the pi.node1 ;</li><li>3º Pi is the pi.node2;</li></ul><p>Edit the following files:</p><p>(this needs to be done manually on each Pi)</p><ul><li>/etc/hosts, add the following:</li></ul><pre>192.168.1.115 pi.master<br>192.168.1.116 pi.node1<br>192.168.1.117 pi.node2</pre><ul><li>/etc/hostname , change its value:</li></ul><pre># using master as example<br>pi.master</pre><p>Once completed, we also need to reboot the Pi. Now, when the terminal is opened, instead of:</p><pre>pi@raspberrypi:~ $</pre><p>We should use:</p><pre>pi:pi.master:~ $</pre><h4>SSH — fine tune</h4><h4>Setup the SSH aliases</h4><p>Edit the ~/.ssh/config with the same same configuration as we have used above (Identify our Pies in the network step):</p><pre>Host pi.master<br>HostName 192.168.1.115<br>User pi</pre><pre>Host pi.node1<br>HostName 192.168.1.116<br>User pi</pre><pre>Host pi.node2<br>HostName 192.168.1.117<br>User pi</pre><h4>Setup public/private key pairs</h4><p>On each Pi, run the following command:</p><pre>$ ssh-keygen -t ed25519</pre><p>This command generates a public and private key pair within the ~/.ssh directory which can be used a securely ssh connection without the need of typing a password.</p><p>ℹ️ no passphrase is needed to protect the access to the key pair.</p><ul><li>Concatenate the public keys into the authorized_keys:</li></ul><p>On the slaves Pis, run the following command:</p><pre>$ cat ~/.ssh/id_ed25519.pub | ssh pi@192.168.1.115 &#39;cat &gt;&gt; .ssh/authorized_keys&#39;</pre><p>ℹ️ 192.168.1.115 is the pi.master IP address</p><p>On the pi.master, run the following command:</p><pre>$ cat .ssh/id_ed25519.pub &gt;&gt; .ssh/authorized_keys</pre><p>From this moment, the master is able to connect to the slaves through ssh in an easy way.</p><pre>#ie: ssh to master<br>$ ssh pi.master</pre><h4>Sync the SSH configuration</h4><p>To replicate the passwordless ssh on all the slaves, run the following commands:</p><pre>$ scp ~/.ssh/authorized_keys pi.nodeX:~/.ssh/authorized_keys<br>$ scp ~/.ssh/config pi.nodeX:~/.ssh/config</pre><p>⚠️ pi.nodeX: the <strong>X</strong> represents the index of the slaves</p><h3>Helpers</h3><h4>Create scripts</h4><p>As developers, we are lazy… Let’s create a few bash scripts in our ~/.bashrc :</p><ul><li>Get hostname slaves:</li></ul><pre>function nodes {<br>  grep &quot;pi&quot; /etc/hosts | awk &#39;{print $2}&#39; | grep -v $(hostname)<br>}</pre><ul><li>Run commands on all cluster:</li></ul><pre>function cluster_cmd {<br>  for pi in $(nodes); do ssh $pi &quot;$@&quot;; done<br>  $@<br>}</pre><ul><li>Reboot cluster:</li></ul><pre>function cluster_reboot {<br>  cluster_cmd sudo shutdown -r now<br>}</pre><ul><li>Send file to cluster:</li></ul><pre>function cluster_scp {<br>  for pi in $(nodes); do<br>    cat $1 | ssh $pi &quot;sudo tee $1&quot; &gt; /dev/null 2&gt;&amp;1<br>  done<br>}</pre><h4>Sync in the cluster</h4><p>Now, its’ time to also add these helpers into the entire cluster.</p><pre>$ source ~/.bashrc &amp;&amp; cluster_scp ~/.bashrc</pre><h3><strong>Java</strong></h3><p>Hadoop 3.2.0 <a href="https://cwiki.apache.org/confluence/display/HADOOP/Hadoop+Java+Versions">requires Java 8 </a>. You might need to change for this version.</p><ul><li>Download Java 8:</li></ul><pre>$ sudo apt install openjdk-8-jdk</pre><ul><li>Set Java version:</li></ul><pre>$ sudo update-alternatives --config java</pre><p>The default version will have a * next to it. Type a selection number and hit Enter to set a different Java version as the system default.</p><p>(this should to be done manually on each Pi)</p><p>Now that the initial setup is completed… <strong>First we will create a single-node setup on the </strong><strong>pi.master and then, we will set the multi node cluster.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*dLsHNIxeNdIKg3npykZBow.gif" /></figure><h3>Single setup</h3><p>On pi.master:</p><h4>Download and extract the Hadoop</h4><ul><li><strong>Download</strong>:</li></ul><pre>$ cd &amp;&amp; wget <a href="https://archive.apache.org/dist/hadoop/common/hadoop-3.2.0/hadoop-3.2.0.tar.gz">https://archive.apache.org/dist/hadoop/common/hadoop-3.2.0/hadoop-3.2.0.tar.gz</a></pre><ul><li><strong>Extract</strong>:</li></ul><pre>$ sudo tar -xvvf hadoop-3.2.0.tar.gz -C /opt/<br>$ rm hadoop-3.2.0.tar.gz<br>$ cd /opt<br>$ sudo mv hadoop-3.2.0 hadoop</pre><p>Then, there is the need to change the owner permissions on Hadoop’s directory:</p><pre>$ sudo chown pi:pi -R /opt/hadoop</pre><h4>Environment vars</h4><p>Edit the following commands:</p><ul><li>~/.bashrc:</li></ul><pre>export JAVA_HOME=$(readlink -f /usr/bin/java | sed &quot;s:bin/java::&quot;)<br>export HADOOP_HOME=/opt/hadoop<br>export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin</pre><ul><li>/opt/hadoop/etc/hadoop/hadoop-env.sh:</li></ul><pre>export JAVA_HOME=$(readlink -f /usr/bin/java | sed &quot;s:bin/java::&quot;)</pre><h4>HDFS</h4><p>To get the HDFS up and running, we need to modify the following files located on /opt/hadoop/etc/hadoop :</p><ul><li>core-site.xml:</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;fs.defaultFS&lt;/name&gt;<br>    &lt;value&gt;hdfs://pi.master:9000&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><ul><li>hdfs-site.xml:</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;dfs.datanode.data.dir&lt;/name&gt;<br>    &lt;value&gt;file:///opt/hadoop_tmp/hdfs/datanode&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;dfs.namenode.name.dir&lt;/name&gt;<br>    &lt;value&gt;file:///opt/hadoop_tmp/hdfs/namenode&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;dfs.replication&lt;/name&gt;<br>    &lt;value&gt;1&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><ul><li>mapred-site.xml:</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;mapreduce.framework.name&lt;/name&gt;<br>    &lt;value&gt;yarn&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><ul><li>yarn-site.xml :</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.nodemanager.aux-services&lt;/name&gt;<br>    &lt;value&gt;mapreduce_shuffle&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>   &lt;name&gt;yarn.nodemanager.auxservices.mapreduce.shuffle.class&lt;/name&gt;  <br>    &lt;value&gt;org.apache.hadoop.mapred.ShuffleHandler&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><p>⚠️️ The hdfs-site.xml defines where the DataNode and NameNode store the data and also sets the replication. Due to this, we also need to create these folders with the right privileges:</p><pre>$ sudo mkdir -p /opt/hadoop_tmp/hdfs/datanode<br>$ sudo mkdir -p /opt/hadoop_tmp/hdfs/namenode<br>$ sudo chown pi:pi -R /opt/hadoop_tmp</pre><p>Once we’ve edited the config files, the next step is to format the HDFS</p><pre>$ hdfs namenode -format -force</pre><p>Boot the HDFS with the following command:</p><pre>$ $HADOOP_HOME/sbin/start-dfs.sh<br>$ $HADOOP_HOME/sbin/start-yarn.sh</pre><h4>… time to test!</h4><p>… through the command jps, it should display the following services</p><pre>ResourceManager<br>NameNode<br>Jps<br>SecondaryNameNode<br>DataNode<br>NodeManager</pre><p>… or, by creating a temporary directory:</p><pre>$ hadoop fs -mkdir /tmp</pre><pre>$ hadoop fs -ls/<br>Found 1 items<br>drwxr-xr-x   - pi supergroup          0 2021-06-05 20:04 /tmp</pre><h4>Hide annoying NativeCodeLoader warnings</h4><p>We might see the warning util.NativeCodeLoader: Unable to load native-hadoop library(…). This warning isn’t easy to solve, basically we could recompile the library from scratch on the 64-bit machine, but for this tutorial it is enough to hide it.</p><p>Add the following commands on the ~/.bashrc:</p><pre>$ export HADOOP_HOME_WARN_SUPPRESS=1<br>$ export HADOOP_ROOT_LOGGER=&quot;WARN,DRFA&quot;</pre><h3>Cluster setup</h3><p>At this moment, we have a single node that works as master and slave node. It’s time to setup our cluster.</p><h4>Create Hadoop directories</h4><p>Through the following commands, we will create the mandatory folders on all slave Pis.</p><pre>$ cluster_cmd sudo mkdir -p /opt/hadoop_tmp/hdfs<br>$ cluster_cmd sudo chown pi:pi –R /opt/hadoop_tmp<br>$ cluster_cmd sudo mkdir -p /opt/hadoop<br>$ cluster_cmd sudo chown pi:pi /opt/hadoop</pre><h4>Sync Hadoop config</h4><p>Copy all the files from the opt/hadoop on all the slave Pis.</p><pre>$ for pi in $(nodes); do rsync -avxP $HADOOP_HOME $pi:/opt/; done</pre><h4>Configuring Hadoop on Cluster</h4><p>Edit the following config files located on /opt/hadoop/etc/hadoop</p><ul><li>core-site.xml, add the following:</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;fs.default.name&lt;/name&gt;<br>    &lt;value&gt;hdfs://pi.master:9000&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><ul><li>hdfs-site.xml, add the following:</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;dfs.datanode.data.dir&lt;/name&gt;<br>    &lt;value&gt;/opt/hadoop_tmp/hdfs/datanode&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;dfs.namenode.name.dir&lt;/name&gt;<br>    &lt;value&gt;/opt/hadoop_tmp/hdfs/namenode&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;dfs.replication&lt;/name&gt;<br>    &lt;value&gt;2&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><ul><li>mapred-site.xml, add the following:</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;mapreduce.framework.name&lt;/name&gt;<br>    &lt;value&gt;yarn&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.app.mapreduce.am.resource.mb&lt;/name&gt;<br>    &lt;value&gt;256&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;mapreduce.map.memory.mb&lt;/name&gt;<br>    &lt;value&gt;128&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;mapreduce.reduce.memory.mb&lt;/name&gt;<br>    &lt;value&gt;128&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><ul><li>yarn-site.xml, add the following:</li></ul><pre>&lt;configuration&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.acl.enable&lt;/name&gt;<br>    &lt;value&gt;0&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.resourcemanager.hostname&lt;/name&gt;<br>    &lt;value&gt;pi.master&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.nodemanager.aux-services&lt;/name&gt;<br>    &lt;value&gt;mapreduce_shuffle&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;&lt;name&gt;yarn.nodemanager.auxservices.mapreduce.shuffle.class&lt;/name&gt;  <br>    &lt;value&gt;org.apache.hadoop.mapred.ShuffleHandler&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.nodemanager.resource.memory-mb&lt;/name&gt;<br>    &lt;value&gt;900&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.scheduler.maximum-allocation-mb&lt;/name&gt;<br>    &lt;value&gt;900&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.scheduler.minimum-allocation-mb&lt;/name&gt;<br>    &lt;value&gt;64&lt;/value&gt;<br>  &lt;/property&gt;<br>  &lt;property&gt;<br>    &lt;name&gt;yarn.nodemanager.vmem-check-enabled&lt;/name&gt;<br>    &lt;value&gt;false&lt;/value&gt;<br>  &lt;/property&gt;<br>&lt;/configuration&gt;</pre><p>On $HADOOP/etc/hadoop/ we need to create two files for Hadoop to identify the master and which ones are the slaves.</p><ul><li>Create a file named master with the single line:</li></ul><pre>pi.master</pre><ul><li>Create a file name worker and add the slaves (one per line):</li></ul><pre>pi.node1<br>pi.node2</pre><p>Edit the /etc/hosts and remove the line:</p><pre>127.0.0.1 pi.master</pre><p>Now, let’s copy the hosts file to all the slaves:</p><pre>$ cluster_scp /etc/hosts</pre><p>… reboot the cluster:</p><pre>$ cluster_reboot</pre><h3>Start Hadoop Cluster</h3><p>On pi.master run the command:</p><pre>$ hdfs namenode -format -force</pre><p>Now, boot the HFDS:</p><pre>$ $HADOOP_HOME/sbin/start-dfs.sh<br>$ $HADOOP_HOME/sbin/start-yarn.sh</pre><h4>Is it working?</h4><p>Through the command hdfs dfsadmin -report we should have the similar output:</p><pre>Configured Capacity: 60373532672 (56.23 GB)<br>Present Capacity: 41064591360 (38.24 GB)<br>DFS Remaining: 41064542208 (38.24 GB)<br>DFS Used: 49152 (48 KB)<br>DFS Used%: 0.00%<br>Replicated Blocks:<br> Under replicated blocks: 0<br> Blocks with corrupt replicas: 0<br> Missing blocks: 0<br> Missing blocks (with replication factor 1): 0<br> Low redundancy blocks with highest priority to recover: 0<br> Pending deletion blocks: 0<br>Erasure Coded Block Groups: <br> Low redundancy block groups: 0<br> Block groups with corrupt internal blocks: 0<br> Missing block groups: 0<br> Low redundancy blocks with highest priority to recover: 0<br> Pending deletion blocks: 0</pre><pre>-------------------------------------------------<br>Live datanodes (2):</pre><pre>Name: 192.168.1.116:9866 (pi.node1)<br>Hostname: pi.node1<br>Decommission Status : Normal<br>Configured Capacity: 30186766336 (28.11 GB)<br>DFS Used: 24576 (24 KB)<br>Non DFS Used: 8399671296 (7.82 GB)<br>DFS Remaining: 20462870528 (19.06 GB)<br>DFS Used%: 0.00%<br>DFS Remaining%: 67.79%<br>Configured Cache Capacity: 0 (0 B)<br>Cache Used: 0 (0 B)<br>Cache Remaining: 0 (0 B)<br>Cache Used%: 100.00%<br>Cache Remaining%: 0.00%<br>Xceivers: 1<br>Last contact: Sat Jun 05 21:49:42 WEST 2021<br>Last Block Report: Sat Jun 05 21:41:48 WEST 2021<br>Num of Blocks: 0</pre><pre>Name: 192.168.1.117:9866 (pi.node2)<br>Hostname: pi.node2<br>Decommission Status : Normal<br>Configured Capacity: 30186766336 (28.11 GB)<br>DFS Used: 24576 (24 KB)<br>Non DFS Used: 8260870144 (7.69 GB)<br>DFS Remaining: 20601671680 (19.19 GB)<br>DFS Used%: 0.00%<br>DFS Remaining%: 68.25%<br>Configured Cache Capacity: 0 (0 B)<br>Cache Used: 0 (0 B)<br>Cache Remaining: 0 (0 B)<br>Cache Used%: 100.00%<br>Cache Remaining%: 0.00%<br>Xceivers: 1<br>Last contact: Sat Jun 05 21:49:42 WEST 2021<br>Last Block Report: Sat Jun 05 21:41:48 WEST 2021<br>Num of Blocks: 0</pre><p>… We also have a web interface (http://pi.master:9870) where we can explore the cluster info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pkNco6spIGrc_HIbV-cArg.png" /><figcaption>Hadoop Web UI interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rrUoUZChgULYhCCZEctFaA.png" /><figcaption>Data node information</figcaption></figure><h3>Conclusion</h3><p>And… That’s it folks! Now we have installed a Raspberry Pi Hadoop cluster.</p><p>I hope this guide has been helpful to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlbRJH45srmjlm1sqOQhSA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fbcc0fc19a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ElasticSearch — This is how you should paginate your results]]></title>
            <link>https://tmateus.medium.com/elasticsearch-this-is-how-you-should-paginate-your-results-5d1c71bfe060?source=rss-3516b9a4353b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d1c71bfe060</guid>
            <category><![CDATA[pagination]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[cursor-based-pagination]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Tiago Mateus]]></dc:creator>
            <pubDate>Mon, 06 Jul 2020 10:49:26 GMT</pubDate>
            <atom:updated>2020-07-16T21:54:26.202Z</atom:updated>
            <content:encoded><![CDATA[<h3>ElasticSearch — This is how you should paginate your results</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*A_ENoh90fh-9UAoqoY8eeQ.png" /></figure><p>Whether you are building the next Google or a simple MVP, <strong>pagination</strong> is something you should be doing well from the beginning and that is something that is often missed.</p><p>Today, we will see two different approaches and which one is the most efficient one and that you should use it.</p><p>Let’s assume just for an example that we would have a social network and we would be building a functional requirement where the user would be able to search his/her followers and filter through them.</p><p>In a REST <strong>API</strong> level, we will need to create an <strong>endpoint</strong> to handle this <strong>search</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*tloPKWAI5T4j9R8cR_chSQ.png" /></figure><p>On <strong>ElasticSearch</strong>, <strong>setting</strong> the <strong>OFFSET</strong> and <strong>LIMIT</strong> is a <strong>simple task</strong>. In <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html"><strong>_search method</strong></a>, we have the following properties that we can use:</p><ul><li>size: it’s our “limit“ (how many items should be brought)</li><li>from: it’s our offset (from where to start the search)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*nHDPhxbesPNK4_pR33dRcA.png" /></figure><p>In the example above, <strong>ES</strong> (<strong>ElasticSearch</strong>) will <strong>search the documents</strong> with a limit of 1000 elements from the 100th position.</p><p>At this point, we all agree that <strong>ElasticSearch is perfect for this task</strong>… So,<strong> is there any reason we would need to be careful?</strong></p><p>Let’s continue with the same values as the example above and let’s assume that this index has 4 shards. <strong>Each shard will generate</strong> 1100 <strong>results for the </strong><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html#coordinating-node"><strong>coordinator node</strong></a>, who will receive a total of 4400 (4 shards * 1100 results) and <strong>only</strong> then <strong>extracts</strong> the <strong>needed</strong> 1000 <strong>results</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*5-OJMSxBAzc0maonK5aWAg.png" /></figure><p>… And this will happen <strong>every time we perform this call. </strong>ElasticSearch will calculate by each shard individually and send each one to the coordinator node. Due to this, we should avoid using this approach if our goal is to have a scalable result paginator despite of the amount of documents we have.</p><p>Now that we understood the problem, <strong>what is the solution?</strong></p><p><strong>Most of the time, the pagination is used sequentially </strong>(page 1, page 2, page 3 and so on…). If we keep this in mind… Then, we should use the <strong>keyset pagination</strong> (<strong>or cursor based pagination</strong>). The idea is to <strong>think as a pointer</strong> and <strong>avoid</strong> the workload of <strong>doing all the calculations every time</strong> we need the next slice of results.</p><p><strong>ElasticSearch has the </strong><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-scroll"><strong>scroll property</strong></a> that will<strong> “magically“ solve</strong> this performance issue.</p><p>In the first call we add the scroll parameter, parameter from which ES will know that this search is going to be “cursor paginated“ and also how long it will keep the search context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*sz2ayjPrM7FcGLDiIiKfew.png" /><figcaption><strong>1m</strong> means 1 minute of <strong>expiration time</strong></figcaption></figure><p>… and the payload response will also return a scroll_id referring to the pointer of the next “slice” of documents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*WvKgnwh3HzCg-7E4cyAalQ.png" /></figure><p>Internally <strong>ElasticSearch</strong> will<strong> filter and order</strong> a <strong>list of documents</strong> grouped by 1000 elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*yjnNNg9feq4y7Z7zEC_Mjw.png" /></figure><p>So, to performantly <strong>paginate through our results</strong>, we will <strong>still use</strong> the <strong>search method</strong>, however with the difference of using scroll and scroll_id as represented below. This should <strong>work performantly</strong>, <strong>not mattering the number of results to paginate through</strong>. And again but this time in the body, we have the scroll parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*hrI-3uWX71mbxjP8ctkmfQ.png" /></figure><p>Now, <strong>ElasticSearch</strong> will return the next chunk of documents <strong>without</strong> the need of <strong>calculating everything again</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*cpcqpJH-zLKcPMG-vO2fow.png" /></figure><h3>Conclusion</h3><p>The <strong>scroll method</strong> has been created to work with an unknown number of results and be always efficient <strong>without</strong> the need to <strong>recalculate</strong> the entire process <strong>every time</strong> we request the next slice of documents. Offset should be avoided whenever possible and a <strong>cursor</strong> should be used instead.</p><p>If you want to know more about cursor pagination in MySQL, have a look at <a href="https://medium.com/swlh/why-you-shouldnt-use-offset-and-limit-for-your-pagination-4440e421ba87">Why You Shouldn’t Use OFFSET and LIMIT For Your Pagination</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d1c71bfe060" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>