Hello,

I've built a version of a 'Google Instant Search' on Drupal using Views JSON & Search API. The problem I'm having is that the Drupal stack is taking too long to return the results (even though Solr itself seems to be pretty much instant).

What options have I got for improving the performance, or should I query the Solr server directly, and bypass the Drupal stack?

Comments

couturier’s picture

Do you think it could be a slowdown with your server rather than against the Drupal stack?

chrism2671’s picture

You mean the solr server? I don't think so. We're running on pantheon (nginx, redis, varnish) - that's very quick. I tried hitting another (different) solr directly, and it's much, much faster than via views. Normally it would be ok, but if the results need to be delivered in sub key stroke time, I really need to find a way to optimise it as much as possible.

drunken monkey’s picture

If you want to optimise it “as much as possible”, Drupal is probably out of the question, at least for the AJAX callback. If you use Drupal for that, it will have to be bootstrapped for each AJAX request separately before there is anything sent to Solr. While certainly not easy, bypassing this has a huge potential for performance gains, which I don't think you'll be able to get otherwise.

couturier’s picture

It doesn't get much faster than Pantheon when you're running Drupal. Maybe this function isn't possible in Drupal, as per comment #3.

chrism2671’s picture

Yeah I had suspected so. If I understand correctly, the results from Solr are quite well formatted, so it should be pretty to contact the server directly using JS from the browser, parse it and produce meaningful results? I've seen this in 'example' cases, although not tried it with Solr API Search's schema.xml.

drunken monkey’s picture

Yes, you even get JSON back (and with a well-defined structure) so handling this in Javascript should be trivial. The query also shouldn't be too hard to setup. The main work will probably be theming the results in JS.
However, I don't think you'll be able to contact the Solr server directly via AJAX. Firstly, the browser's same-origin policy might prevent you from doing that, even though it's just the port that's different. Secondly, your Solr server would have to be accessible from the outside for that, which I'd strongly discourage. This would effectively eliminate all security on the Solr server, people would be able to make arbitrary queries on it and even (the really bad part) add, edit or delete documents in your index.

So, there's probably no avoiding a small script on your web server that passes the query on. But since that could be almost trivial (just a pass-through for request and response, with a few safety checks) and even implemented directly in C with CGI, that probably won't make any real difference performance-wise.

chrism2671’s picture

I think that's a plan, Pantheon's Solr servers are firewalled so that's really the only option. I'm not sure exactly what the security implications would be (in order to write the security checks) - I'll have to research those, but I think that's the main plan.

drunken monkey’s picture

Well, first off you should make sure that only the /select handler can be reached this way – any access to /update should of course be prohibited. Other than that, the restrictions would (as far as I can see) just be the ones imposed by your application – e.g., if you have unpublished nodes indexed which normal users shouldn't see, be sure to always pass a bs_status:true filter. The downside of circumventing Drupal is of course the lack of authentication (unless you choose it's worth the performance penalty and additional work to somehow still access the login information), so you can't display more content to admins (or other special groups) than to normal users.

chrism2671’s picture

It might be worth writing a short PHP script to do all the authentication stuff without a full bootstrap (questionable whether this is actually feasible/secure); it might be 'hacky', but it may also be the only way of actually doing 'instant' type functionality with Drupal.

pinkonomy’s picture

If you write a php script,can you post it here or as a module?

OanaIlea’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

This issue was closed due to lack of activity over a long period of time. If the issue is still acute for you, feel free to reopen it and describe the current state.