The Wayback Machine - https://web.archive.org/web/20171220123711/http://apache.sys-con.com:80/node/3280800

Welcome!

Apache Authors: Pat Romanski, Liz McMillan, Elizabeth White, Christopher Harrold, Janakiram MSV

Related Topics: @CloudExpo, Apache, @DevOpsSummit

@CloudExpo: Blog Feed Post

Solr Redis Plugin Use Cases By @Sematext | @DevOpsSummit [#DevOps]

The Solr Redis Plugin is an extension for Solr that provides a query parser that uses data stored in Redis

Solr Redis Plugin Use Cases and Performance Tests

The Solr Redis Plugin is an extension for Solr that provides a query parser that uses data stored in Redis. It is open-sourced on Github by Sematext. This tool is basically a QParserPlugin that establishes a connection to Redis and takes data stored in SET, ZRANGE and other Redis data structures in order to build a query. Data fetched from Redis is used in RedisQParser and is responsible for building a query. Moreover, this plugin provides a highlighter extension which can be used to highlight parts of aliased Solr Redis queries (this will be described in a future).

Use Case: Social Network
Imagine you have a social network and you want to implement a search solution that can search things like: events, interests, photos, and all your friends' events, interests, and photos. A naive, Solr-only-based implementation would search over all documents and filter by a "friends" field. This requires denormalization and indexing the full list of friends into each document that belongs to a user. Building a query like this is just searching over documents and adding something like a "friends:1234″ clause to the query. It seems simple to implement, but the reality is that this is a terrible solution when you need to update a list of friends because it requires a modification of each document. So when the number of documents (e.g., photos, events, interests, friends and their items) connected with a user grows, the number of potential updates rises dramatically and each modification of connections between users becomes a nightmare. Imagine a person with 10 photos and 100 friends (all of which have their photos, events, interests, etc.).  When this person gets the 101th friend, the naive system with flattened data would have to update a lot of documents/rows.  As we all know, in a social network connections between people are constantly being created and removed, so such a naive Solr-only system could not really scale.

Social networks also have one very important attribute: the number of connections of a single user is typically not expressed in millions. That number is typically relatively small - tens, hundreds, sometimes thousands. This begs the question: why not carry information about user connections in each query sent to a search engine? That way, instead of sending queries with clause "friends:1234," we can simply send queries with multiple user IDs connected by an "OR" operator. When a query has all the information needed to search entities that belong to a user's friends, there is no need to store a list of friends in each user's document. Storing user connections in each query leads to sending of rather large queries to a search engine; each of them containing multiple terms containing user ID (e.g., id:5 OR id:10 OR id:100 OR ...) connected by a disjunction operator. When the number of terms grows the query requests become very big. And that's a problem, because preparing it and sending it to a search engine over the network becomes awkward and slow.

How Does It Work?
The image below presents how Solr Redis Plugin works.

  1. The client application sends simple and very small query to Solr. That query contains only a simple fragment which calls Solr Redis Plugin. You can read more about it in the "How to use the plugin?" section.
  2. Solr Redis Plugin takes a connection from a connection pool and sends a command to Redis.
  3. Redis sends a response. The response format depends on the Redis command in the request. Redis can return just a set of records, or a set of records with scores. When the Solr Redis Parser receives a Redis response it takes the records and builds a Lucene boolean query. By default the OR operator is used, but it can be changed to the AND operator.
  4. Solr Redis Plugin returns the Lucene query to Solr, which executes it and sends matches back to the client application.

Solr Redis Plugin Data Flow
Of course, we can achieve similar functionality by making the client application responsible for communication with Redis. This solution moves the entire responsibility for establishing and handling connections with Redis to the client application.

  1. The client application sends a Redis command.
  2. The client application receives a Redis response, parses it, and prepares a Solr Query.
  3. Very big query is sent to Solr.
  4. Solr parses big query, searches for results and sends a response to the client application.

Data Flow without Solr Redis Plugin
As we can see, Solr Redis Plugin eliminates a lot of work that client application doesn't have to be aware of:

Solr Redis Plugin Client Application approach
Establishing connections to Redis Connection handled by client app
Keeping connection pool which
accelerates communication
No connection pool by default
It has to be created by a client app
Small Solr queries Large Solr queries

Project Location

The project is available on Github. You can clone the repository at https://github.com/sematext/solr-redis.git. Patches are welcome. There is also a package in the central maven repository com.sematext:solr-redis.

How to Use the Plugin?

Configuration
Solr Redis Plugin
is simply a QParserPlugin that is very easy to deploy in a Solr instance. The plugin classes are packaged into a JAR file. You can also download a pre-built package from Maven (that JAR file has to be moved to Solr classpath, of course). For example, you can simply copy the solr-redis.jar file to $SOLR_HOME/lib directory.  To use it, add the following snippet to solrconfig.xml and restart Solr:

<queryParser name="redis" class="com.sematext.solr.redis.RedisQParserPlugin">
<str name="host">localhost</str>
<str name="maxConnections">30</str>
<str name="retries">2</str>
</queryParser>

Querying
Solr Redis is a QParserPlugin, so the syntax is similar to other QParserPlugins such as frange, term or boost. To use the plugin in a query you need to run a query such as:

{!redis command=smembers key=KEY}FIELD

The constructions presented above can be used in both q and fq Solr parameters. The example of the whole request with filter query is presented below.

http://localhost:8983/solr/collection/select?q=*:*&fq={!redis command=smembers key=KEY}FIELD

KEY - is a Redis key used to look up values.

FIELD - is a name of a field which will be queried. Field has to exist in index schema. You can use any of field types: text fields, string fields or numeric fields.

In most cases you can use Solr Redis Plugin in both q and fq. Often, it is better to use a plugin as a filter query. Using the plugin as a filter lets Solr cache the filter using FilterCache, which will speed up all user searches.

Let's go back to the Social Network example for a moment. User X may want to search not only documents related to his friends, but also documents related to friends of friends. Perhaps documents from a group of friends should be scored more highly than documents from other friends. To do this we can use scoring from Redis sorted set. Each record in the sorted set can have a different scoring value. The query to Solr that uses sorted set scoring is shown below. Please note that in this example the Solr Redis Plugin is used in q. That's because Solr doesn't calculate scoring of filter query. Here we cannot use fq because we need Solr to do the scoring using scores from sorted set.

http://localhost:8983/solr/collection/select?q={!redis command=zrevrangebyscore key=KEY min=100 max=1000}FIELD

Logging
The Solr Redis Plugin logs a few messages which are helpful to understand when Redis is queried, what data is fetched from Redis, which Redis command was used, or when an error occurred. You can easily manage logging level using Solr Admin UI.

Performance Tests
At Sematext we care a lot about performance; in fact, we built SPM, a comprehensive performance monitoring, alerting and anomaly detection solution.   Not only does it monitor Solr (here's a demo of Solr being monitored), but many other types of applications as well.  We also frequently tune Solr performance for our clients in our Solr Consulting engagements.  So, of course, we ran a performance test of Solr Redis Plugin!

Dataset
In the first test, 1,000,000 simple documents were indexed in Solr. Each document represents a user with an ID from 1 to 1,000,000. The second thing was to generate connections between users, done randomly with a simple python script. Each user had between 1 and 1,000 connections (avg. was 500). Once we prepared the data it was time to run performance tests. Tests were performed to compare results of Solr Redis Plugin to an approach with simple filter query with multiple "OR" clauses. We generated a query set. All tests were performed with Apache JMeter using 5 threads.  JMeter was run from the same machine where Solr was deployed. It is not ideal test environment because it won't show the biggest advantage of the plugin - sending very big queries over the network, but we also wanted to show that even on the same machine using the Solr Redis Plugin is more efficient than using big filter queries.

Tests run on Intel Core2 Duo [email protected], 8GB RAM. Solr used Oracle JDK 1.7 u51 with default GC settings. Because of default GC settings we can see periodical peaks of latency on diagrams.

Results

Test 1
Results in the table and images below present performance tests for both the Solr Redis Plugin and a filter query with multiple terms. The average number of connections between users was 500. We can see that using Solr Redis Plugin is a bit faster than sending big queries to Solr. It is very important that queries are already prepared so measured latency doesn't include the time needed to generate a query. In a real-world scenario queries should also be generated by application which also take time (getting data from Redis and constructing a query string before sending it to Solr).


Samples Avg. time[ms] Median time[ms] 90-th percent. time[ms] Requests per second
SolrRedisPlugin 30000 60 52 111 78.3
Big filter query 30000 71 60 141 67.5

SolrRedisPlugin - 30000 queries - avg. 500 connections between users Filter query - 30000 queries - avg. 500 connections between users (avg 500 boolean clauses)

Test 2
Below we can see results of the test which was very similar to the previous one except the average number of connections between users was 5,000.


Samples Avg. time[ms] Median time[ms] 90-th percent. time[ms] Requests per second
SolrRedisPlugin 2000 587 522 1047 8.46
Big filter query 2000 766 649 1349 6.47

SolrRedisPlugin - 2000 queries - avg. 5000 connections between users Filter query - 2000 queries - avg. 5000 connections between users (avg 5000 boolean clauses)

You have to remember that HTTP URL size is limited, and unless you change the setting in the container or you use POST requests instead of GET you would be unable to run queries with hundreds or thousands clauses in a filter.

Summary
This post describes the Solr Redis Plugin. We showed an example of usage of the plugin for handling queries in a social network. Using such a plugin is much more convenient, efficient and scalable than generating filter queries with hundreds or thousands of terms. Performance tests show that it is more efficient to use the plugin instead of sending large queries to Solr over the network. We should not forget tests were performed in an environment where JMeter was sending queries from the same machine where Solr was running. This means our tests involved almost no network traffic, which means the results for a pure Solr approach without Solr Redis Plugin would be even worse than queries been going over the network to a remote Solr instance.

More Stories By Sematext Blog

Sematext is a globally distributed organization that builds innovative Cloud and On Premises solutions for performance monitoring, alerting and anomaly detection (SPM), log management and analytics (Logsene), and search analytics (SSA). We also provide Search and Big Data consulting services and offer 24/7 production support for Solr and Elasticsearch.

@ThingsExpo Stories
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L; stakeholders.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...