<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>utilizenode &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/utilizenode-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://solr.pl/en/</link>
	<description>All things to be found - Blog related to Apache Solr &#38; Lucene projects - https://solr.apache.org</description>
	<lastBuildDate>Sat, 14 Nov 2020 14:21:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Solr 7.2 &#8211; rebalancing replicas using UTILIZENODE</title>
		<link>https://solr.pl/en/2018/01/02/solr-7-2-rebalancing-replicas-using-utilizenode/</link>
					<comments>https://solr.pl/en/2018/01/02/solr-7-2-rebalancing-replicas-using-utilizenode/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Tue, 02 Jan 2018 14:20:50 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[utilizenode]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=951</guid>

					<description><![CDATA[With the release of Solr 7.2 we got a new option in the Collections API &#8211; the ability to utilize a new or existing node of our cluster based on the autoscaling properties. It basically looks at the replicas placement]]></description>
										<content:encoded><![CDATA[<p>With the release of Solr 7.2 we got a new option in the Collections API &#8211; the ability to utilize a new or existing node of our cluster based on the autoscaling properties. It basically looks at the replicas placement and using the autoscaling rules for the cluster and collection allows us to automatically move replicas to a given node. Sounds nice in theory, so let&#8217;s look how it actually works.</p>
<p><span id="more-951"></span></p>
<h3>Autoscaling API in Solr</h3>
<p>If you are not aware what the Autoscaling API in Solr is let me quickly get you up to date on that. That API allows us to set cluster-wide or per collection rules that tell Solr how it should allocate shards and replicas in the cluster. We want to take node CPU utilization into consideration &#8211; sure, we can do that. We want to utilize the information about the free disk space on the nodes &#8211; of course, we can do that. The very nice thing is that the rules can be set for both collections and for the whole cluster. That gives us flexibility &#8211; we can set general rules for shard allocation and force certain rules per collection if that is needed.</p>
<p>However, the allocation rules are only used during shard assignment. Which means that once we have the shards assigned and ready Solr will not use the stored information anymore. At least that was the case till Solr 7.2. Will 7.2 we have the ability to rebalance the cluster situation using the <em>UTILIZENODE</em> command.</p>
<h3>Test environment</h3>
<p>For ease of repeating the same test I&#8217;ll be using very simple environment based on Solr 7.2. I&#8217;ll start two nodes, first one using the following command:
</p>
<pre>$ bin/solr start -c</pre>
<p>And the second node using the following command:
</p>
<pre>$ bin/solr start -z localhost:9983 -p 6683</pre>
<p>In addition to that I&#8217;ll create a single collection called <em>test</em> which will be initially built out of a single shard and I&#8217;ll add 3 replicas, all on the same node. So my final view of the cluster will look as follows:</p>
<p><a href="https://solr.pl/wp-content/uploads/2017/12/cluster_before_load_balancing.png"><img decoding="async" class="aligncenter wp-image-4058" src="https://solr.pl/wp-content/uploads/2017/12/cluster_before_load_balancing-300x47.png" alt="" width="450" height="70"></a></p>
<p>Its cluster state looks as follows:
</p>
<pre>{"test":{
    "pullReplicas":"0",
    "replicationFactor":"1",
    "router":{"name":"compositeId"},
    "maxShardsPerNode":"1",
    "autoAddReplicas":"false",
    "nrtReplicas":"1",
    "tlogReplicas":"0",
    "shards":{"shard1":{
        "range":"80000000-7fffffff",
        "state":"active",
        "replicas":{
          "core_node2":{
            "core":"test_shard1_replica_n1",
            "base_url":"http://192.168.1.15:8983/solr",
            "node_name":"192.168.1.15:8983_solr",
            "state":"active",
            "type":"NRT",
            "leader":"true"},
          "core_node4":{
            "core":"test_shard1_replica_n3",
            "base_url":"http://192.168.1.15:8983/solr",
            "node_name":"192.168.1.15:8983_solr",
            "state":"active",
            "type":"NRT"},
          "core_node6":{
            "core":"test_shard1_replica_n5",
            "base_url":"http://192.168.1.15:8983/solr",
            "node_name":"192.168.1.15:8983_solr",
            "state":"active",
            "type":"NRT"},
          "core_node8":{
            "core":"test_shard1_replica_n7",
            "base_url":"http://192.168.1.15:8983/solr",
            "node_name":"192.168.1.15:8983_solr",
            "state":"active",
            "type":"NRT"}}}}}}
</pre>
<p>As you can see all the replicas are on the same node, the one with <em>base_url</em> equal to <em>http://192.168.1.15:8983/solr</em>.</p>
<p>So we have the following situation:</p>
<ul>
<li>We have Solr cluster built of two nodes</li>
<li>We have a single collection working in the cluster</li>
<li>Our collection is built of 4 shards &#8211; one leader and three replicas</li>
<li>All shards are assigned to a single node</li>
</ul>
<p>Basically we are not utilizing one of the nodes. Let&#8217;s try changing that situation by using the <em>UTILIZENODE</em> command of the Solr Collections API introduced in Solr 7.2.</p>
<h3>Collections API UTILIZENODE in works</h3>
<p>To show you how the Autoscaling API works we will first create a cluster wide preference. By using the following command we will tell Solr to try to evenly balance the cluster on the basis of the number of replicas in each of the nodes:
</p>
<pre>$ curl -XPOST 'localhost:8983/api/cluster/autoscaling' -H 'Content-Type:application/json' -d '{
 "set-cluster-preferences" : [
  {"minimize": "cores"}
 ]
}'</pre>
<p>The above command sets the cluster wide shard allocation preferences and tells Solr to minimize the number of cores that is present on each node. Which means that Solr will try to balance the cores across all the nodes.</p>
<p>So now, using the <em>UTILIZENODE</em> command from the Collections API we will try to force Solr to automatically move some of the replicas. The call to the Collections API looks as follows:
</p>
<pre>$ curl -XGET 'localhost:8983/solr/admin/collections?action=UTILIZENODE&amp;node=192.168.1.15:6683_solr'</pre>
<p>The&nbsp;<em>node</em> parameter is required because we need to tell Solr which node we consider underutilized. The processing of the command can take a longer period of time, so please consider running it in a async mode. However one the command ends its execution we should see the following in the cloud view:</p>
<p><a href="https://solr.pl/wp-content/uploads/2017/12/cluster_after_load_balancing.png"><img decoding="async" class="aligncenter wp-image-4059" src="https://solr.pl/wp-content/uploads/2017/12/cluster_after_load_balancing-1024x144.png" alt="" width="450" height="63"></a></p>
<p>The cluster state after rebalancing changed as well and now looks as follows:
</p>
<pre>{"test":{
    "pullReplicas":"0",
    "replicationFactor":"1",
    "shards":{"shard1":{
        "range":"80000000-7fffffff",
        "state":"active",
        "replicas":{
          "core_node6":{
            "core":"test_shard1_replica_n5",
            "base_url":"http://192.168.1.15:8983/solr",
            "node_name":"192.168.1.15:8983_solr",
            "state":"active",
            "type":"NRT",
            "leader":"true"},
          "core_node8":{
            "core":"test_shard1_replica_n7",
            "base_url":"http://192.168.1.15:8983/solr",
            "node_name":"192.168.1.15:8983_solr",
            "state":"active",
            "type":"NRT"},
          "core_node10":{
            "core":"test_shard1_replica_n9",
            "base_url":"http://192.168.1.15:6683/solr",
            "node_name":"192.168.1.15:6683_solr",
            "state":"active",
            "type":"NRT"},
          "core_node12":{
            "core":"test_shard1_replica_n11",
            "base_url":"http://192.168.1.15:6683/solr",
            "node_name":"192.168.1.15:6683_solr",
            "state":"active",
            "type":"NRT"}}}},
    "router":{"name":"compositeId"},
    "maxShardsPerNode":"1",
    "autoAddReplicas":"false",
    "nrtReplicas":"1",
    "tlogReplicas":"0"}}</pre>
<p>As you can see two replicas have been moved &#8211; from the <em>192.168.1.15:8983_solr</em> node to <em>192.168.1.15:6683_solr</em> node, which is exactly what our cluster preferences were telling Solr to do.</p>
<h3>Summary</h3>
<p>The <em>UTILIZENODE</em> from the Collections API is a form of automation of cluster management. Of course we could do the same by using the <em>ADDREPLICA</em> and <em>DELETEREPLICA</em> commands, but we would have to manually keep the cluster and collection policies in mind and be sure we are not violating any of the settings that are already present. The <em>UTILIZENODE</em> command gives us all that and allows us to force utilization of a given node in the cluster according to the policies that we already defined.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2018/01/02/solr-7-2-rebalancing-replicas-using-utilizenode/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
