{"id":990,"date":"2019-04-15T16:07:46","date_gmt":"2019-04-15T14:07:46","guid":{"rendered":"http:\/\/sematext.solr.pl\/?p=990"},"modified":"2020-11-14T16:08:17","modified_gmt":"2020-11-14T15:08:17","slug":"solr-8-bytebuffersdirectory-quick-look","status":"publish","type":"post","link":"https:\/\/solr.pl\/en\/2019\/04\/15\/solr-8-bytebuffersdirectory-quick-look\/","title":{"rendered":"Solr 8 &#8211; ByteBuffersDirectory &#8211; quick look"},"content":{"rendered":"\n<p>One of the new features introduced in the recently released Solr 8.0 is new implementation of the <em>Directory<\/em> interface &#8211; one that will replace not scalable <em>RAMDirectory<\/em>. The new implementation called <em>ByteBuffersDirectory<\/em> is dedicated to small, short lived data that is held only in memory. Let&#8217;s have a quick look into potential use cases, advantages and drawbacks of this new implementation.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Configuration<\/h2>\n\n\n\n<p>Simplest things first &#8211; let&#8217;s start with configuration. This time the situation is very simple. The only thing that we need to take care of is proper <em>DirectoryFactory<\/em> implementation in the <em>solrconfig.xml<\/em> file, file example<\/p>\n\n\n\n<pre class=\"wp-block-code\">&lt;directoryFactory name=\"DirectoryFactory\" class=\"solr.ByteBuffersDirectoryFactory\" \/&gt;<\/pre>\n\n\n\n<p>One thing we need to remember though is the <em>lockType<\/em> implementation. At the time of writing, the only possible value for <em>lockType<\/em> when <em>ByteBuffersDirectoryFactory<\/em> is used is <em>simple<\/em>. No other lock type is supported.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Possible Usage<\/h2>\n\n\n\n<p>The new implementation of the <em>Directory<\/em> interface will replace <em>RAMDirectory<\/em> &#8211; implementation that is present in Lucene and Solr for a long period of time now. However, keep in mind that <em>RAMDirectory<\/em> is not suggested to be used because of its issues. <\/p>\n\n\n\n<p>Theortically we should use the in-memory <em>Directory<\/em> implementation for small, short lived Lucene indices. This allows us to avoid disk usage for writes and reads for potentially higher indexing throughput and lower query latency.<\/p>\n\n\n\n<p>For example, you can use the newly introduced <em>Directory<\/em> implementation for keeping highly updated data like number of products or for that needed only once &#8211; i.e. reports coming from multiple data sources. <\/p>\n\n\n\n<p>You need to remember though that similar to <em>RAMDirectory<\/em>, the <em>ByteBuffersDirectory<\/em> doesn&#8217;t save data to disk. This means that you need to re-index your data after each Solr restart or failure. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advantages<\/h2>\n\n\n\n<p>The main advantage, that we already mentioned, is that the data indexed to the core\/collection that uses <em>ByteBuffersDirectory<\/em> will not use disk resources. That means that the data write and read will be blazingly fast, which can result in higher indexing throughput and lower query latency. However keep in mind that similar behavior can be achieved when using <em>mmap<\/em> calls to the I\/O subsystem of the operating system, so for example when using the <em>MMapDirectory<\/em>. This <em>Directory<\/em> implementation shares the I\/O cache of the operating system and will re-use data that is put in memory by the operating system. The second advantage, especially when compared to the <em>RAMDirectory<\/em> is that the <em>ByteBuffersDirectory<\/em> fully supports multi-threading, so we won&#8217;t have issues when using the multi-threaded data indexing and access.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Drawbacks<\/h2>\n\n\n\n<p>Of course not everything is bright and shining, there are also drawbacks when using the <em>ByteBuffersDirectory<\/em> &#8211; we should mention three things here. First of all, when using this directory, the data will be volatile &#8211; every restart will require data re-indexing. It is one of the principles of that <em>Directory<\/em> implementation, but it is worth remembering about that. The second thing is heap memory. If the data will be stored on heap it will mean more heap memory usage and more work for the garbage collector, which can lead to less performance. Finally &#8211; we are partially limited by the amount of physical memory and the memory assigned to the JVM heap. This means that the core\/collections that are using <em>ByteBuffersDirectory<\/em> shouldn&#8217;t be too large.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the new features introduced in the recently released Solr 8.0 is new implementation of the Directory interface &#8211; one that will replace not scalable RAMDirectory. The new implementation called ByteBuffersDirectory is dedicated to small, short lived data that<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[27],"tags":[617,619,164],"class_list":["post-990","post","type-post","status-publish","format-standard","hentry","category-solr-en","tag-8-0-2","tag-directory-2","tag-solr-2"],"_links":{"self":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/comments?post=990"}],"version-history":[{"count":1,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/990\/revisions"}],"predecessor-version":[{"id":991,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/posts\/990\/revisions\/991"}],"wp:attachment":[{"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/media?parent=990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/categories?post=990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solr.pl\/en\/wp-json\/wp\/v2\/tags?post=990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}