<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oshan Wisumperuma</title>
    <description>The latest articles on DEV Community by Oshan Wisumperuma (@oshanwisumperuma).</description>
    <link>https://dev.to/oshanwisumperuma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F38266%2Ff8d2a910-5613-4e79-9625-741e21fe1cc2.jpg</url>
      <title>DEV Community: Oshan Wisumperuma</title>
      <link>https://dev.to/oshanwisumperuma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oshanwisumperuma"/>
    <language>en</language>
    <item>
      <title>Elasticsearch Tune for indexing speed</title>
      <dc:creator>Oshan Wisumperuma</dc:creator>
      <pubDate>Wed, 18 Nov 2020 05:27:59 +0000</pubDate>
      <link>https://dev.to/oshanwisumperuma/elasticsearch-tune-for-indexing-speed-513e</link>
      <guid>https://dev.to/oshanwisumperuma/elasticsearch-tune-for-indexing-speed-513e</guid>
      <description>&lt;h3&gt;
  
  
  Increase the refresh interval and disable replicas
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nsftX4P3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fjalvefrzfcwom6uxhov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nsftX4P3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fjalvefrzfcwom6uxhov.png" alt="Screenshot from 2020-11-18 10-33-54"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On some projects, indexing happens at a different pace, not while the application is in use. In my current project, we follow a similar approach. So I'm disabling the refresh interval because we are not going to search while indexing is on. Also, I'll enable replication when all the indexing complete.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--location&lt;/span&gt; &lt;span class="nt"&gt;--request&lt;/span&gt; PUT &lt;span class="s1"&gt;'localhost:9200/&amp;lt;index&amp;gt;/_settings'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--header&lt;/span&gt; &lt;span class="s1"&gt;'Content-Type: application/json'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;--data-raw&lt;/span&gt; &lt;span class="s1"&gt;'{
    "settings": {
        "index": {
            "number_of_replicas": "0",
            "refresh_interval": "600s"
        }
    }
}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  call GET endpoint to confirm the new variables.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BlDC7TRb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7kxl6ntahvr4cpmpdy7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BlDC7TRb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7kxl6ntahvr4cpmpdy7w.png" alt="Screenshot from 2020-11-18 10-33-29"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--location&lt;/span&gt; &lt;span class="nt"&gt;--request&lt;/span&gt; GET &lt;span class="s1"&gt;'localhost:9200/&amp;lt;index&amp;gt;/_settings'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;collecting these values initially will be helpful, so you can reset the configurations after indexing is complete.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  bulk insert
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KHPm3RYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gt5vf8sn0gyb90kdljjy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KHPm3RYZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gt5vf8sn0gyb90kdljjy.png" alt="Screenshot from 2020-11-18 10-45-23"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;adjust the batch size of the elasticsearch-model &lt;code&gt;import&lt;/code&gt; function argument.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;API: &lt;a href="https://rubydoc.info/gems/elasticsearch-model/Elasticsearch/Model/Importing/ClassMethods#import-instance_method"&gt;https://rubydoc.info/gems/elasticsearch-model/Elasticsearch/Model/Importing/ClassMethods#import-instance_method&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;more tips can be found from here: &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html#tune-for-indexing-speed"&gt;https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html#tune-for-indexing-speed&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>elasticsearch</category>
      <category>rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>How to create faster smaller swap space</title>
      <dc:creator>Oshan Wisumperuma</dc:creator>
      <pubDate>Sat, 17 Oct 2020 19:37:00 +0000</pubDate>
      <link>https://dev.to/oshanwisumperuma/how-to-create-a-swap-storage-using-zram-3m0f</link>
      <guid>https://dev.to/oshanwisumperuma/how-to-create-a-swap-storage-using-zram-3m0f</guid>
      <description>&lt;p&gt;Even though swap is not necessary for the most of use cases, but developers might need swap space when doing a big compilation, browsing on chrome or on slack. but it is a really painful experience using a swap partition on Disk space. ZRAM helps us allocate small storage from RAM as swap space and store 3,4 times of data on that space. its even faster than the SSD swap partitions because this is a ram drive.&lt;/p&gt;

&lt;p&gt;Since &lt;a href="https://facebook.github.io/zstd"&gt;zstd&lt;/a&gt; has an excellent compression ratio, 2GB of zram space will have total swap capacity around 6GB. please note that these commands are only tested on Fedora 32. All the changes will be lost in the next reboot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;modprobe zram &lt;span class="nv"&gt;num_devices&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;zstd &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /sys/block/zram0/comp_algorithm
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;2G &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /sys/block/zram0/disksize
&lt;span class="nv"&gt;$ &lt;/span&gt;mkswap &lt;span class="nt"&gt;--label&lt;/span&gt; zram0 /dev/zram0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  enable the swap partition with higher priority
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;$ swapon --priority 1 /dev/zram0&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Tadaa! 🎉  now we can open another chrome tab ;-)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;free &lt;span class="nt"&gt;-h&lt;/span&gt;
              total        used        free      shared  buff/cache   available
Mem:           15Gi       7.3Gi       1.8Gi       1.5Gi       6.4Gi       6.4Gi
Swap:         2.0Gi       5.0Mi       2.0Gi

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  to disable the swap storage
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;$ swapoff /dev/zram0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;update: zram is enabled by default &lt;/p&gt;

</description>
      <category>linux</category>
      <category>tips</category>
      <category>sysadmin</category>
      <category>fedora</category>
    </item>
  </channel>
</rss>
