<?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 SAYAN DAS on Medium]]></title>
        <description><![CDATA[Stories by SAYAN DAS on Medium]]></description>
        <link>https://medium.com/@poke19962008?source=rss-b9f010ec1377------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kIcRCi2uRYh0Vg5jZ0rLwg@2x.jpeg</url>
            <title>Stories by SAYAN DAS on Medium</title>
            <link>https://medium.com/@poke19962008?source=rss-b9f010ec1377------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:53:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@poke19962008/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[Scaling Search by Sharding at Blibli]]></title>
            <link>https://medium.com/bliblidotcom-techblog/everything-you-need-to-know-about-migrating-solr-collection-to-multi-shard-983a881f9054?source=rss-b9f010ec1377------2</link>
            <guid isPermaLink="false">https://medium.com/p/983a881f9054</guid>
            <category><![CDATA[e-commerce-business]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[solr]]></category>
            <category><![CDATA[search]]></category>
            <category><![CDATA[blibli]]></category>
            <dc:creator><![CDATA[SAYAN DAS]]></dc:creator>
            <pubDate>Thu, 16 Dec 2021 13:40:31 GMT</pubDate>
            <atom:updated>2021-12-17T05:58:37.213Z</atom:updated>
            <content:encoded><![CDATA[<p>As the production of BliBli’s search grows each year in terms of number of catalogs with a steady rate of 30% per year so does the catalog updates along with that. In BliBli we use Apache Solr to power our search systems, with just single shard since 2017. Since then our catalog size has grown 15x and average requests per minutes by ~13x (as of Q3 of 2021). Although the numbers looks very ravishing, but for our Solr collection running in just a single shard it was clinging to its last breaths. Given, we use expensive query components like faceting over 12 different fields, collapsing, stats and query time synonym expansion in every request.</p><blockquote>Given the situation we did our math for the upcoming anniversary sale for Q3 2021 with the estimated projected traffic, our search systems won’t scale. Hence giving us just 1 month before the sales to scale the systems to sail through the event with 0 downtime and keeping the response times below the SLAs. Here is how sharding our collection to achieve the record high request throughput with the record low response times, during sales.</blockquote><h3>When you should shard your collection?</h3><p>Here are few symptoms you should be looking out in your systems to know it’s the time:</p><ul><li><em>High garbage collection time:</em> with the growing index size <a href="https://lucene.apache.org/core/8_0_0/core/org/apache/lucene/search/IndexSearcher.html">IndexSearcher</a>, will collect lot more relevant documents with every search request, thus resulting in huge pile of dead objects to clean up. We saw a very slow but a steady rate of increase in GC CPU time with the growing index. We can tune the systems up to certain level (do check out <a href="https://medium.com/bliblidotcom-techblog/optimizing-solr-resources-with-g1-448bb9c49d46">this</a> article on how we tuned our search system), but after some extent it will give up.</li><li><em>High memory consumption:</em> Systems will suffer a memory crunch and need to increase the VM memory every month. The crunch won’t be from user memory used by Solr JVM but instead there be crunch in OS buffer caches, because Lucene is trying to fit the entire index segments inside it. When there OS could not fit more index segments on buffer, in that case our disk will take a hit with high read ops resulting in high response time.</li><li><em>Frequent OOMs while doing faceting</em>: With the huge index faceting over a high cardinality field is expensive operation often leading to OOM</li><li><em>Rising infrastructure cost</em>: With the growing hunger for memory and compute for garbage collection, our search infrastructure was digging a big hole in our pocket.</li></ul><h3>How to? — Sharding / Document routing</h3><p>Now you know, you need to shard your collection here is how you will do it. Optimal way depends upon the type of query (or the business use case)which we are having and data is organized in a collection</p><h4>Routed Search</h4><p>This mechanism works the best when we know while querying from which shard all the documents should be queried from. We can pass _route_ param along with the query to redirect query to correct shard. Here in the example below we have sharded the collection on the basis of location. Now when user want to search “samsung” product in stores at Jakarta it will automatically redirect the query to correct shard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UmZH-RZk2R77hhDITaswHA.png" /></figure><p>Solr use MurmurHash64 to hash the route, then determines which bucket it falls into. Buckets are created whenever we create a new collection and the range can be seen in the Solr admin UI. In the example above hash function returned 25, which lies in between 21 to 32 of shard3.</p><p>For BliBli we have the same sharding strategy for the merchants selling products in multiple stores all over Indonesia. Merchant code and the store location are used to create composite key and all the data is served from one single shard.</p><p>This type of system is easy to scale, because let’s say if any one or multiple shards are over shooting the index, we simply split the shard.</p><h4>Distributed Search</h4><p>There comes a scenario where you don’t know from which shard the search results will come from. This is the type of architecture which we followed back in ’21 Q3 for online product collection, where 95% of search request in BliBli lands. Here is how it works,</p><p><strong><em>Fetch TOP_IDS:</em></strong> clients asks to fetch the results for the query “samsung”, it hit any one replica of “each” shard to fetch just the top document Ids and score (thus this phase is called as fetch TOP_IDS). Basically query q=samsung&amp;fl=id,score&amp;shards=shard_i where i ={1, 2, 3}, parallely in each shard. On our example below documents were present in shard1 and shard3 only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n0psbO5gWwyvnAPmTR9S-g.png" /><figcaption>Fetch TOP_IDS</figcaption></figure><p><strong><em>Fetch GET_FIELDS:</em></strong> Now, the results are aggregated and sorted on the basis of lucene score. The rest of the fields are fetched in the second phase, from the targeted shards (in our example just shard1 and shard2). Query will look something like this, q=id:x,y,z&amp;fl=*&amp;shards=shard1 (considering in TOP_ID it fetched x, y and z documents from shard1) and q=id:p,q&amp;fl=*&amp;shards=shard2 (and p and q from shard2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yfkl6eXyhqxoZXb8YHkEDg.png" /><figcaption>Fetch FIELDS</figcaption></figure><p>The results are stitched together, and returned to the client. This phenomenon can be easily traced by passing “debug=track” in the request and observing the requestPurpose field.</p><p>There will be TPᵢₙₜₑᵣ Solr calls for single search page Solr call. Here N is the number of shards. The first N calls will gather the top ID, facet counts (if facet=true) and lucene score i.e EXECUTE_QUERY → GET_TOP_IDS along with GET_FACETS. In the second part, ‘i’ calls are made to fetch the meta data i.e GET_FIELDS which will contact respective shards and gather the data from any of the replia of that shard.</p><blockquote><strong>TPᵢₙₜₑᵣ= (N + i) ∀ i ∈ {0, 1,2, … N}</strong></blockquote><p>TPᵢₙₜₑᵣ increases with the number of shards linearly, thus making these types of system difficult to scale upto a certain extent. We will discuss more on this below.</p><h3>Checklist for designing the system</h3><p>Now we know how we query in a multi sharded collection, here are few things you need to be careful while migrating your collection to multi shard. Please make a note this checklist is subjected to distributed search only.</p><h4>Dealing with skewed data distribution</h4><p>One should know how the data is distributed in the collection, there can be scenario that the data can be highly skewed resulting in imbalanced shard index size. For example, possibly there will be too many stores in Jakarta as compared to other provinces in Indonesia because it’s the country capital.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*epmaqjSPhYG-WzxjlKQeNg.png" /><figcaption>Index size per shard</figcaption></figure><p>Skewness can be easily verified from Solr admin UI &gt; Nodes, under Disk Usage in Solr v8.0.0 and above. <a href="https://solr.apache.org/guide/8_11/shards-and-indexing-data-in-solrcloud.html#document-routing">Here</a> is official Solr documentation which tells how you can use 2 levels of routing to reduce the skewness upto an extent.</p><p>And h<a href="https://www.youtube.com/watch?v=_Erkln5WWLw">ere is how Apple manages</a> to tackle the issue by automating the shard split, in their work flow.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_Erkln5WWLw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_Erkln5WWLw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_Erkln5WWLw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7cf2593ab0cf683d4f537b85c6be167/href">https://medium.com/media/a7cf2593ab0cf683d4f537b85c6be167/href</a></iframe><h4>Determining correct number of shard</h4><p>The most common question we get how many shards is right amount for us. Well it all “depends”, upon the workload, query type and how many documents are we dealing with. For starters, we use this thumb rule to determine the shard, let’s say my collection can handle upto ‘x’ number of documents, currently it has ‘y’ documents, and yearly increase in catalogue size is ’n’ times the previous year. And we wanna make the system future proof till ‘z’ years</p><blockquote><strong>num_shards = ceil(y*(1 + z*n)/x)</strong></blockquote><p>That will give a rough idea, but to verify the numbers we projected the number of documents we will expect in the next 5years and ran the test with shard number as variable and plotted mean latency vs number of shard graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZSwM0vBLlcUbmcgpbclPKg.png" /><figcaption>baseline vs extrapolated collection with variable # shards</figcaption></figure><p>For the collections having routed search, as mentioned above they are easy to scale, because each search request is dependent on specific subset or single shard only. But with distributed search approach it gets trickier to handle significantly more inter shard calls happening, consuming the JVM threads.</p><h4>Hardware configuration</h4><p>To have a higher availability, you have to need more VMs to power the Solr cluster, but because index size will be small we can have very less resources on each of the VMs. In our case, we found out after the migration we reduced the overall CPU cores and memory of our entire collection as compared with single shard but increased the total number of VMs.</p><p>For the initial capacity planning we calculated the total number of cores and memory we have in single shard. Let’s say we have 10 nodes with each having 4cores and 20gb memory, so in total 4*10=40cores and 20*10=200gb of memory. I will try to fit and rearrange the replicas within 20nodes of 2cores and 10gb. This really helped us in determining the total capacity of multi sharded collection in finite resource. Later while moving ahead to production we can upscale according to our requirement.</p><h4><strong>Replica Placement</strong></h4><p>BliBli’s data center is hosted in Google Cloud Platform, Singapore southeast region. When the replica’s are arranged across different regions, there can be network over head while distributing the requests. You can refer Google’s real-time cross region latency matrix from <a href="https://datastudio.google.com/reporting/fc733b10-9744-4a72-a502-92290f608571/page/70YCB">here</a>.</p><p>Hence while arranging the replica we make sure the replicas are evenly distributed in nodes hosted in all the regions.</p><h4>Configurations worth considering</h4><p>Few things you may wanna configure to avoid possible disruption as soon as production traffic hits your new collection:</p><ul><li><strong>ShardHandlerFactory thread pool configuration</strong>: As mentioned above with the increasing shard in the limited number of nodes can increase inter solr calls, that will eventually increase the number of active threads in JVM. Here is the <a href="https://solr.apache.org/guide/8_1/distributed-requests.html#configuring-the-shardhandlerfactory">official documentation</a>.</li><li><strong>ShardHandlerFactory connection timeouts: </strong>Now there is inter dependency of one shard to another. Any perf bottle neck in one of the shard replica can quickly escalate to other shards as well, hence it’s become necessary to quickly release the threads by configuring appropriate lower timeouts. You will find the configuration in the same documentation above.</li><li><strong>Partial results: </strong>Consider the same situation as above, in case of complete or partial shard outages, Solr by defaults fails the request any one of the shard returns non 2xx status. You may want to update the solr config or pass <a href="https://solr.apache.org/guide/8_8/solrcloud-query-routing-and-read-tolerance.html#shards-tolerant-parameter">this param</a> with every request</li><li><strong>Single Pass mechanism: </strong>With the sufficient network bandwidth and while we are fetching only few fields, we can enable <a href="https://solr.apache.org/guide/8_8/solrcloud-query-routing-and-read-tolerance.html#shards-tolerant-parameter">distrib.singlePass</a> to completely eliminate FETCH_METADATA phase completely, reducing the number of active JVM threads. But it may lead to other issues like memory utilization and network bandwidth reaching limits.</li></ul><h3>Conclusion</h3><p>BliBli search saw huge improvement when we moved to distributed search in-terms of response time by whooping 65% and reduced infrastructure cost. Which helped to sail through BliBli ’21 anniversary event, with no hiccups.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=983a881f9054" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bliblidotcom-techblog/everything-you-need-to-know-about-migrating-solr-collection-to-multi-shard-983a881f9054">Scaling Search by Sharding at Blibli</a> was originally published in <a href="https://medium.com/bliblidotcom-techblog">Blibli.com Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Solr Resources, with G1]]></title>
            <link>https://medium.com/bliblidotcom-techblog/optimizing-solr-resources-with-g1-448bb9c49d46?source=rss-b9f010ec1377------2</link>
            <guid isPermaLink="false">https://medium.com/p/448bb9c49d46</guid>
            <category><![CDATA[apachasolr]]></category>
            <category><![CDATA[blibli]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[solr]]></category>
            <category><![CDATA[garbage-collection]]></category>
            <dc:creator><![CDATA[SAYAN DAS]]></dc:creator>
            <pubDate>Thu, 24 Dec 2020 12:19:47 GMT</pubDate>
            <atom:updated>2022-04-21T14:39:31.636Z</atom:updated>
            <content:encoded><![CDATA[<h3>Optimizing Solr Resources with G1</h3><h3>Introduction</h3><p>Java community is continuously evolving at a very rapid pace. With java 9, it deprecated famous Concurrent Mark Sweep GC Collector, in favor of new G1 collector. Engineers can resist anything except giving their application beefier resources. Especially when it comes to memory hungry Solr, luring us to turn the heap up. This article will be focused on tunning G1 GC params in Solr and tell</p><blockquote>how <a href="http://blibli.com/">blibli.com</a>‘s search gained major performance gains with limited resources by just adding 11 lines of configurations!</blockquote><h3>G1 Collector Overview</h3><p>In this section I will cover basic concept of how G1 works and key concepts which are essential while configuring collector on Solr. I won’t cover entire working of G1 but here are few articles to refer <a href="https://plumbr.io/handbook/garbage-collection-algorithms-implementations/g1">[1]</a> and <a href="https://docs.oracle.com/javase/9/gctuning/garbage-first-garbage-collector.htm#JSGCT-GUID-E9CB81BC-92E5-489E-8A2E-760691A41CDF">[2]</a>. Moving on, if you are using JDK 9 (in later part, we will discuss why it is not recommended to use JDK 9 and lower, if you are planning to upgrade to G1) and on wards, JVM by default ships with G1 collector rather that Parallel GC. You can also enable G1 collector in JDK 7 update 4 and later by using <strong>-XX:+UseG1GC</strong> on command line JVM parameters. The key point which makes G1 different from other collectors is the grid style heap layout, heap is equally partitioned into small equally spaced cells of memory each cell can be either free or occupied by young or old generation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yp0oLRkyfio23xGe7jIiJw.png" /><figcaption>G1 Heap Region</figcaption></figure><p>Size of each individual cell can be configured with <strong>-XX:G1HeapRegionSize=n </strong>JVM parameter, by default the region size is allocated by maxHeapSize/2048 and rounded down to the first power of 2 between 1MB and 32MB; region sizes &lt;1MB or &gt;32MB are not supported.</p><h4>Humongous Allocation</h4><p>There can be situation in which an object is bigger than an individual free cell size, and may required multiple contiguous free cells to fit in. These objects are called humongous objects, and these objects play a crucial role in tuning G1 collector on Solr. Conditions that qualify to be humongous is when the object size exceeds 50% of heap region size i.e -XX:G1HeapRegionSize and these are assigned contiguous set of regions. JVM treats such objects bit differently they can be reclaimed during any type of collection cycle (well depends if you are using JDK 8u40 <a href="https://bugs.openjdk.java.net/browse/JDK-8048179">JDK-8048179</a> or else they will be reclaimed in full garbage collection, here is a good article explaining how eager reclamation works for humongous object <a href="https://blogs.oracle.com/poonam/eager-reclamation-of-humongous-objects-with-g1">[4]</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6zFJRRH3aQoE9afzWEEbuQ.png" /></figure><h4>Heap Region and Generation</h4><p>Nothing special here it’s just like other collectors. Quoting official documentation from Oracle</p><blockquote><em>The vast majority of objects are allocated in a pool dedicated to young objects (the young generation), and most objects die there. When the young generation fills up, it causes a minor collection in which only the young generation is collected; garbage in other generations isn’t reclaimed. The costs of such collections are, to the first order, proportional to the number of live objects being collected; a young generation full of dead objects is collected very quickly. Typically, some fraction of the surviving objects from the young generation are moved to the old generation during each minor collection. Eventually, the old generation fills up and must be collected, resulting in a major collection, in which the entire heap is collected. Major collections usually last much longer than minor collections because a significantly larger number of objects are involved.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVnVSZ70jM9Vbz-tUfjgYQ.png" /><figcaption>Generations in G1</figcaption></figure><h4>CMS vs. G1 Collector</h4><p>Applications running today with either the CMS or the ParallelOld garbage collector would benefit switching to G1 if the application has one or more of the following traits.</p><ul><li>More than 50% of the Java heap is occupied with live data.</li><li>The rate of object allocation rate or promotion varies significantly.</li><li>Undesired long garbage collection or compaction pauses (longer than 0.5 to 1 second)</li></ul><h3>How we optimized Solr with G1</h3><p>One thing clear out, optimizing garbage collection won’t reduce the actual memory requirement, this will only help save extra CPU cycles while doing garbage collection, that will be useful serving requests. For optimizing memory utilization you can refer to this article <a href="https://jprante.github.io/lessons/2012/07/26/Mmap-with-Lucene.html">[3]</a>, with this and optimizing GC you can squeeze out much performance from both CPU and memory front. Moving on, there is no thumb rule to determine the configuration theoretically but it “all depends” on the following factors:</p><ul><li>Size of each documents</li><li>Number of documents present n given node</li><li>Request throughput for query and update requests</li><li>How frequent is index commit</li><li>Numbers of rows trying to fetch in request.</li><li>Fetching all the fields or few fields only</li></ul><p>All the factors are interlinked together, one thing or another may alter GC behavior. Lets see the setup that we used to get our ideal GC configuration and few observations.</p><h4>Experiment Setup</h4><p>For hardware we had 3 VMs with following configuration:</p><ul><li>Operating System: Centos 7.2</li><li>Memory: 32g</li><li>CPU: Intel x86 16cores, Threads per core: 2</li></ul><p>And the Solr configuration we were having was:</p><ul><li>Solr v8.3.1</li><li>Documents: 5million</li><li>Heap configuration: 18g Xms=Xmx</li><li>Single shard</li><li>Java 8</li></ul><p>Each VM running single node with single NRT replica present on each of them as part of single Solr cluster. Further I followed simple “survival of the fittest” to get the final result. We first started with default config (lets say 1st Generation Node 2 β is default configuration) and tinkered (mutated) each parameter at a time i.e 𝛼 and ɣ. Equal load was provided on each node and observed the GC pause, average response time, 95th response time and the request throughput. Best performing setup was used to second generation and repeated the same until we get to the final desired configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZghVyOBQpgM8sI3r" /></figure><p>Instrumenting the application through the process is important. We used NewRelic to observe Solr node’s heap region usage and pauses for minor as well full GCs accordingly we decided which paramater to update for next iteration. But if you don’t have paid license for NewRelic, in that case Grafana and Prometheus will solve the purpose. Or else turn on the GC logs, by attaching following parameters to GC_TUNE variable of Solr’s solr.in.sh file and use some online tool like <a href="https://gceasy.io/">https://gceasy.io/</a> to visualize. GC Easy helped us to understand the GC activity in much more granular way, than even New Relic.</p><p><em>-XX:+PrintGCDetails<br>-XX:+PrintGCDateStamps<br>-XX:+PrintGCCause<br>-XX:+PrintTenuringDistribution<br>-XX:+UseGCLogFileRotation<br>-XX:NumberOfGCLogFiles=10<br>-XX:GCLogFileSize=5M</em></p><h4>Observation #1: Query Analysis</h4><p>Let’s say you are fetching large number of documents (maybe assume rows=100000) but with just fl=id and in another hand you are requesting same rows but with fl=* on separate node, both of them will have very different memory footprint. In Solr every document is an Object and each documents have its own fields that is also Object, so let;s say each document on Solr have 10 String fields. Roughly we can say in the first request i.e rows=100000&amp;fl=id must have created 100000*1 objects and the second request rows=100000&amp;fl=* would have created 100000*10 that is 10x more than the previous and resulting to much aggressive GCs. One thing to note is, such requests on Solr create Objects having very short life span, so as explained earlier if we can fit in those objects in survivor space we can reduce the frequency of full GCs.</p><h4>Observation #2: Humongous Object</h4><p>This is the most critical observation out of all. <strong>By tuning this parameter alone we reduced our garbage collection time by 20x!</strong> On analysis the GC logs we saw most of the time JVM was busy allocating humongous objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*leE2D-sL-jqL3qfG" /><figcaption>Pause for Humongous Object Collection</figcaption></figure><p>This was really concerning as majority of objects were humongous object and JVM was really busy cleaning up those objects. As we know the fact that most of the objects on solr have very small life span, some how if we could put those objects in survivor space then it solve our problem. One way is to increase the region size so that each such object can fit inside 50% of region size. So we increased the region size to 16m, with this we reduced old gen usage and started using survivor space and with that we reduced the GC pauses significantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zgWkNdY5a04xrgmO" /><figcaption>Before</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u6GRWOfFy4wrZDFd" /><figcaption>After</figcaption></figure><h4>Observation #3: JVM Version</h4><p>G1 is default GC with java 9, however it’s present in Java 8 as well but it was in very early stage and you have to be explicit while defining the same. We experimented against java 8 and java 11 specifically. With out tests Java 11 performed significantly better as compared to java 8. Most of the performance gains were from improved garbage collection, and CPU resources were getting utilized better for serving more requests i.e more throughput and there were less pause i.e lower latency. Quantitatively speaking we saw <strong>50% response time gains on j11 as compared with j8</strong>.</p><p>Okay so we have upgraded JDK version. Lets see what new stuffs are packed with the version upgrade. We went through entire release note and bug fixes <a href="https://www.oracle.com/java/technologies/javase/jdk-11-relnote.html">[5]</a>. One particular improvement caught our eye was <a href="https://openjdk.java.net/jeps/307">JEP-307</a>. This is regarding parallelism of major GC fixed in java 10. Here is the thumb rule which we followed to configure the same:</p><p><strong>-XX:ParallelGCThreads=n</strong>. where n = 5/8*(total CPU threads) this should not cross more than 8</p><p><strong>-XX:ConcGCThreads=n</strong> where n = ParallelGCThreads/4</p><h4>Observation #4: Solr Caches and it’s impact on Old gen</h4><p>As discussed earlier, all the objects on Solr are short lived objects and in “ideal” scenarios it should not move to old gen space. But it’s not the case every time. Solr uses different types of solr caches which have much longer time span. Few things which determine the old gen utilization are as following</p><ol><li><strong>Number of caches enabled and cache size:</strong> Higher the cache size means more old gen utilization and more aggressive major GCs</li><li><strong>Auto warm count:</strong> Whenever a new searcher gets open, higher auto warm count means more older objects will get copied, that means less objects getting collected, i.e less<em> aggressive mixed</em> collection</li><li><strong>Commit interval:</strong> with each commit a new searcher gets opened and the older cache gets dropped and the hottest entries gets copied i.e auto warmed. That means more the commit interval less objects are collected.</li></ol><p>By considering the above 3 points and monitoring our cache utilization we configured our old gen space with <strong>-XX:G1NewSizePercent=x</strong> and <strong>-XX:G1MaxNewSizePercent=y.</strong> by adjusting out old gen space we could sustain irregegular surge in traffic efficiently by restricting the flow of extra short spanned objects to old gen space.</p><h3>Conclusion</h3><p>After just customizing our GC parameter we gained</p><blockquote><strong>23% improvement on response time</strong> and <strong>reduced CPU time for Garbage Collection by 95%</strong>.</blockquote><p>Here is how our response time and throughput stacks up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f0H0XEmwQxvGdN39" /><figcaption>Default GC Params</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6ueDjBKDCCqxiyvM" /><figcaption>Custom GC Params</figcaption></figure><p>And the comparison of CPU cycles spent on GC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Bk1ifDUtkW2MSSwr" /><figcaption>Default GC Params</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4-70NbtUKkGBIR4K" /><figcaption>Custom GC Params</figcaption></figure><p>By upgrading JVM to <strong>Java 11 we gained 50% improvement in response time as compared Java 8.</strong>(both setup running on our own custom GC parameters)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_AtqE-6t3n6EeP72" /><figcaption>java8 v. java11</figcaption></figure><p>All the above stats were collected from non-prod environment we further tweaked the parameters in production to support fluctuating traffic better.</p><h3>References</h3><ol><li><a href="https://plumbr.io/handbook/garbage-collection-algorithms-implementations/g1">https://plumbr.io/handbook/garbage-collection-algorithms-implementations/g1</a></li><li><a href="https://docs.oracle.com/javase/9/gctuning/garbage-first-garbage-collector.htm#JSGCT-GUID-E9CB81BC-92E5-489E-8A2E-760691A41CDF">https://docs.oracle.com/javase/9/gctuning/garbage-first-garbage-collector.htm#JSGCT-GUID-E9CB81BC-92E5-489E-8A2E-760691A41CDF</a></li><li><a href="https://jprante.github.io/lessons/2012/07/26/Mmap-with-Lucene.html">https://jprante.github.io/lessons/2012/07/26/Mmap-with-Lucene.html</a></li><li><a href="https://blogs.oracle.com/poonam/eager-reclamation-of-humongous-objects-with-g1">https://blogs.oracle.com/poonam/eager-reclamation-of-humongous-objects-with-g1</a></li><li><a href="https://www.oracle.com/java/technologies/javase/jdk-11-relnote.html">https://www.oracle.com/java/technologies/javase/jdk-11-relnote.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=448bb9c49d46" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bliblidotcom-techblog/optimizing-solr-resources-with-g1-448bb9c49d46">Optimizing Solr Resources, with G1</a> was originally published in <a href="https://medium.com/bliblidotcom-techblog">Blibli.com Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>