Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
couturier CreditAttribution: couturier commentedDo you think it could be a slowdown with your server rather than against the Drupal stack?
Comment #2
chrism2671 CreditAttribution: chrism2671 commentedYou 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.
Comment #3
drunken monkeyIf 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.
Comment #4
couturier CreditAttribution: couturier commentedIt doesn't get much faster than Pantheon when you're running Drupal. Maybe this function isn't possible in Drupal, as per comment #3.
Comment #5
chrism2671 CreditAttribution: chrism2671 commentedYeah 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.
Comment #6
drunken monkeyYes, 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.
Comment #7
chrism2671 CreditAttribution: chrism2671 commentedI 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.
Comment #8
drunken monkeyWell, 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 abs_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.Comment #9
chrism2671 CreditAttribution: chrism2671 commentedIt 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.
Comment #10
pinkonomy CreditAttribution: pinkonomy commentedIf you write a php script,can you post it here or as a module?
Comment #11
OanaIlea CreditAttribution: OanaIlea at bio.logis Genetic Information Management GmbH commentedThis 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.