This was an itch I wanted to scratch. I have been hearing about complaints or worries on the performance of Search API vs. Apachesolr modules. I have used Apachesolr for years, so I was keen to see how Search API would compare.

These tests were done with the exact same set of content. There are only 89 nodes, but they are "real" nodes with real tags.

I performed a search on 'nailsma' (the name of the group and then did a facet filter on Region for the second part.

Please note: this is not scientific by any means, but the proof is in the pudding...

--- Search API Module search page

Facets
- Content type
- Region
- Location
- Keywords
- Project
- Working Together

/search/nailsma - The search found 38 results
Executed 121 queries in 29.93 ms
Executed 120 queries in 33.55 ms
Executed 120 queries in 24.44 ms
Executed 120 queries in 21.22 ms
Executed 121 queries in 21.15 ms
Executed 120 queries in 21.29 ms

/search/nailsma?filter[field_voc_region][0]=%2268%22 - The search found 10 results
Executed 99 queries in 19.11 ms
Executed 99 queries in 18.2 ms
Executed 99 queries in 18.03 ms
Executed 99 queries in 16.52 ms
Executed 99 queries in 20.07 ms

------------------------------------------------------------------------------------
--- Apachesolr Module search page

Facets
- Filter by type
- Filter by Tags
- Filter by Sub Themes
- Filter by Region
- Filter by Location

/search/site/nailsma - Search found 44 items
Executed 161 queries in 23.68 ms.
Executed 161 queries in 22.15 ms.
Executed 161 queries in 26.31 ms.
Executed 161 queries in 34.64 ms.

/search/site/nailsma?filters=im_12_field_voc_region%3A68 - The search found 10 results
Executed 96 queries in 35.18 ms
Executed 96 queries in 16.95 ms
Executed 96 queries in 22.52 ms
Executed 96 queries in 16.74 ms
Executed 96 queries in 19.24 ms

-----------------------------------------------------------------

You can see that Search API holds its own very well indeed and in reality was faster than ApacheSolr. This really caught me off guard, I was expecting ApacheSolr to be easily faster every time.

Importantly, this does not even factor in that Search API can create wonderful view based facet pages anywhere in the site. This flexibility makes it incredibly useful. That was the main reason I jumped ship a week ago from ApacheSolr. I am glad I did and I will definitely not be looking back!

Comments

davidseth’s picture

Oh, forgot to add, I had both set to display 20 results per page.

drunken monkey’s picture

Component: Framework » Miscellaneous
Status: Active » Fixed
Issue tags: +search_api performance

Wow, thanks for doing this! And great to see Search API perform so well!
It's good to now have some independent material on performance. This might well help a lot of others who are unsure about Search API performance. Thanks again!

Tagging your two performance discussions, to link them on the project page.

(Hard to find a fitting category here, but the issue is probably "fixed" in any case.)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

vladady’s picture

Can you increase the number of nodes?
It would be a great test for sites that have a large number many records.
The test results for 10.000, 50.000, 100.000 nodes should be relevant.

It might be better for sites with a lot of content to have the possibility to rely solely on Solr.

Retrieving entities with attached fields implies join operations that decrease performance.
They are already in Solr, so retrieving them when querying Solr would eliminate the joins.

fago’s picture

>Retrieving entities with attached fields implies join operations that decrease performance.

Field API caches those results.

dela.deyoungster’s picture

Issue tags: +ApacheSolr

Sorry to say this, but this is a very naive comparison.

Apache Solr is lauded for its scalability i.e. being able to search and index thousands (and possibly millions) of nodes effectively and efficiently. So jumping to conclusions by benchmarking the performances of two search engines based on just 83 nodes is just down right naive.

As @vladady noted, please test with 10,000 (and more) nodes for a better evaluation of performance.

davidseth’s picture

@dela.deyoungster, what is naive about it? If you would like some different results you would best be served by not approaching the matter with that sort of attitude. This was an itch I needed to scratch a few months back. I had no desire nor any need to test for 10,000 (or more) items so nothing naive about it. I documented exactly what steps I took and how many items I had and answered my questions. I never said anything else.

I didn't jump to any conclusions either. My needs required a highly detailed, faceted search based on views using a smaller set of nodes. Apache Solr can't even come close, but I still wanted to see if performance was going to suffer if I used Search API. Did performance suffer, NO. In fact by using a superior module I was able to get exactly what I wanted, exactly what the client wanted and it was FASTER then Apache Solr module.

Anyway, back to your point. It does not matter how many items are in the index. Search API creates a Solr query (as does Apache Solr module) and sends that to Solr. Solr returns back an answer with a limited set of paged results. There might be 10,000 results, but you only get 10-20 at a time. This is standard across most the web. So Search API will only ever parse those 10-20 items (and as Fago correctly pointed out, they are cached by Field API). That is what my test showed. You would never realistically parse and show 10,000 items in one go. If you wanted to do that Search API wouldn't be your best bet, but I would imagine that even Apache Solr module would also have some difficulties as would your web server as would you web browser with the amount of results.

To your point about efficiency and scalability -- you can see that even Apache Solr module performed the same or more database queries per result then Search API, so this lends additional credence to the efficiencies of the Entity model and Field API and built in caching of those mechanisms. Even Apache Solr module does not deliver pure results straight from the Solr index, it does some processing which decreases its efficiency.

So if you would like tests with 10,000s of nodes please do them. I don't see the relevance for my needs and unless drunken monkey says otherwise (as my above paragraph) there will not be any much if any difference with 1,000s and 10,000s of nodes as you only ever retrieve at most 20 at a time.

bibo’s picture

Subscribing, in case someone decides to do more comparisons. I'm very interested in this subject :)

peterx’s picture

There are a huge number of web sites with pages in the hundreds or low thousands, making small search results relevant. The larger searches might be relevant in a book shop where you forget the name of the author, the book, and search for something else, perhaps "Hogwarts". If a shop sells 10000 computer parts, the shopper selects SSD first then 250GB then searches less than a hundred candidates. If a shop sells five million types of shoes and I select "mens shoes", there will only be three shoes in the search list. For many of my sites, the best test would be a thousand pages, a term selecting one hundred items and the search looking at the one hundred items.

The other consideration is the extra server for Solr. A typical Solr configuration has one server, or VPS for the Web site and another for Solr. If you combine the resources and use just a database search, the database search will run faster.

A valid comparison would be the Web site in a one GB, one GHz VPS with Solr in an identical VPS then compare it to a VPS costing the same as the two separate VPSes. Combining the money will often get you double the CPU power and quadruple the memory. Your whole Web site then screams along and your visitors save far more time than they might save from a small difference between the two searches.

j0rd’s picture

First off, let me mention I'm a fan of Search API, but in my latest project I've been using the ApacheSolr module. So I have experience with both. Much like Search API, I'm actually entity_load'ing my entities after getting the results from solr, just for ease of use and since performance is not yet an issue.

With that said, I've done a lot of performance debugging on my site and I'm going to get my broom and call shenanigans on these benchmark numbers.

--

First off, performing this test on 20 or 10,000 nodes does not matter. 20 is a good result set, as normally you'll be paging the results back from solr at around 20. Both ApacheSolr & Search API perform queries to SOLR and a 100 or 10,000 would really only be testing how each module structures the data in the solr index, not actual performance of displaying a page with the results. I suppose additionally Search API could have the advantage here, as I believe it's possible to limit the amount of fields returned from a document, where apachesolr returns them all. Either way, this shouldn't be what these benchmarks are about. Assuming both modules don't do something stupid by indexing the documents poorly in Solr.

--

Here are my gripes with these numbers. There's lots of factors which seem not to be elaborated on, and thus I don't consider them valid until I hear more details. Thanks again for doing them, but I'm a skeptic. Here's why:

1. Do you have page & block cache off? Results with these caches on, are invalid as they do not test the entire cost of a full un-cached page hit.

2. What time are you measuring? Due to the small 20 ms numbers, I assume you're only measure the time it takes to query solr and not actually the time it takes to render the entire page. Drupal (with out page cache) in my experience can not render a page with nodes in under 20 ms. Additionally we should only be interested in the time it takes to render the entire page as this is where Search API will incur a penalty due to hitting the database.

3. What's your setup? Is you Solr hosted locally? Is you database hosted locally? Database hosted remotely again will penalize Search API as there's additionally latency in those queries and ApacheSolr wouldn't see these performance losses. Having Solr remote should penalize both modules the same I would assume.

4. Are you using an Entity Cache like the entitycache module? This is also important as it will let us determine Search API's speed as it will reduce the need to hit the database. Additionally with only 98 nodes, it would be assumed that all your entities are already pre-cached. This is perhaps a case where one could say testing with 10,000 nodes will make a difference as it's more likely that your nodes are not pre-cached. You should be testing Search API with entitycache's empty, as this is where an entity_load will need to perform the most amount of queries and incur the largest performance hit.

5. What caching backend are you using (Database (default), memcache or redis). This is important for determining the speed of the entity cache.

6. What hardware is this running on? I'm curious because I might have to purchase the same stuff, if I can render my uncached pages with Drupal in under 20 ms.

j0rd’s picture

I finally went through the process of changing my sites most common apachesolr results, to avoid node_load_multiple() and node_view_multiple() and simply style what's returned back from apachesolr.

Here are my initial results after performing this change.

My site does not use page or block view, but relies heavily on memcache and entity cache backends instead. So these stats i refreshed the pages 3 times, then took the xhprof, so those caches would be primed.

This is from a live site. My solr index has ~45,000 entries and these queries are geo-sorts.

Homepage (16 node results, 5x solr queries):
http://i.imgur.com/7KwBJpGh.jpg
Before: 950ms (141k function calls)
After: 480ms (58k function calls)


Search Page (22 node results, 2x solr queries):
http://i.imgur.com/1Ka1RPjh.jpg
Before: 1,300 ms (162k function calls)
After: 304 ms (46k function calls)


This shows what happens when avoiding node_load() with regards to performance. My previous site was about as optimized as possible as well for my node_load_multiples and node_view_multiples, but as you can see, just not calling them at all is a huge win.

PS. COuldn't figure out how attach files with out updating the issue, so uploaded to imgur, which d.org doesn't let us link to it seems:
So here's the imgur album:
http://imgur.com/a/kZ5Xw

charlie charles’s picture

What is the conclusion please?
Is solr or search api faster search?

Many Thanks for your help

j0rd’s picture

I would say, hitting solr with out ever needing to hit the database is faster. I would also say, avoiding views is faster.

Thus I would say, apachesolr module, personally.

With regards to what is faster when page & block cached are turned on, I could not tell you. I would still assume the solution which avoids the database and loading views code is faster.

charlie charles’s picture

I've heard https://drupal.org/project/mongodb is very good too.
But I haven't tried it yet