Perceived performance of REST API

Wednesday, 7 November 2018 · 4 messages
SZ
Sebastian Zimmer7 Nov 2018 14:32 #
Hi, I'm looking for a way to increase the *perceived* performance of the REST API. On my web page there's a results list that is updated automatically when the text content of an input field is changed. This means that on each keystroke by the user, a GET request to the REST API api is sent to obtain the new results list. One GET request takes about 800 ms, which is acceptable to me given the complexity of the query and the amount of data. The problem is that when the user types faster than the queries are executed, the app starts to respond very slowly, because there are now several requests pending. BaseX seems to execute all of them in parallel and it may well take up to 14 seconds until it returns the results of the most recent search query. Is there a way to tell BaseX to abort running queries (by a specific user) to privilege the most recent query (of this user)? Could this be done with the Jobs module? Or is there a better way to implement such a search? Best regards, Sebastian
-- Sebastian Zimmer sebastian.zimmer at uni-koeln.de <mailto:sebastian.zimmer at uni-koeln.de> Cologne Center for eHumanities <http://cceh.uni-koeln.de> DH Center at the University of Cologne @CCeHum <https://twitter.com/CCeHum>
FE
Fabrice ETANCHAUD7 Nov 2018 14:36 #
Hi Sebastian, You should switch to the REST-XQ interface, There is a %rest :single annotation [1] dedicated to that problem. Best regards, Fabrice Etanchaud CERFrance PCH [1] http://docs.basex.org/wiki/RESTXQ
Quoted text · Sebastian Zimmer · 18 lines
De : BaseX-Talk [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de Sebastian Zimmer Envoyé : mercredi 7 novembre 2018 14:32 À : 'BaseX' Objet : [basex-talk] Perceived performance of REST API Hi, I'm looking for a way to increase the *perceived* performance of the REST API. On my web page there's a results list that is updated automatically when the text content of an input field is changed. This means that on each keystroke by the user, a GET request to the REST API api is sent to obtain the new results list. One GET request takes about 800 ms, which is acceptable to me given the complexity of the query and the amount of data. The problem is that when the user types faster than the queries are executed, the app starts to respond very slowly, because there are now several requests pending. BaseX seems to execute all of them in parallel and it may well take up to 14 seconds until it returns the results of the most recent search query. Is there a way to tell BaseX to abort running queries (by a specific user) to privilege the most recent query (of this user)? Could this be done with the Jobs module? Or is there a better way to implement such a search? Best regards, Sebastian -- Sebastian Zimmer sebastian.zimmer at uni-koeln.de<mailto:sebastian.zimmer at uni-koeln.de> Cologne Center for eHumanities<http://cceh.uni-koeln.de> DH Center at the University of Cologne @CCeHum<https://twitter.com/CCeHum>
SZ
Sebastian Zimmer7 Nov 2018 15:15 #
Exactly what I was looking for, thanks. Best regards, Sebastian
Quoted text · Fabrice ETANCHAUD · 57 lines
Am 07.11.2018 um 14:36 schrieb Fabrice ETANCHAUD: > > Hi Sebastian, > > You should switch to the REST-XQ interface, > > There is a %rest :single annotation [1] dedicated to that problem. > > Best regards, > > Fabrice Etanchaud > > CERFrance PCH > > [1] http://docs.basex.org/wiki/RESTXQ > > *De :*BaseX-Talk [mailto:basex-talk-bounces at mailman.uni-konstanz.de] > *De la part de* Sebastian Zimmer > *Envoyé :* mercredi 7 novembre 2018 14:32 > *À :* 'BaseX' > *Objet :* [basex-talk] Perceived performance of REST API > > Hi, > > I'm looking for a way to increase the *perceived* performance of the > REST API. > > On my web page there's a results list that is updated automatically > when the text content of an input field is changed. This means that on > each keystroke by the user, a GET request to the REST API api is sent > to obtain the new results list. > > One GET request takes about 800 ms, which is acceptable to me given > the complexity of the query and the amount of data. > > The problem is that when the user types faster than the queries are > executed, the app starts to respond very slowly, because there are now > several requests pending. BaseX seems to execute all of them in > parallel and it may well take up to 14 seconds until it returns the > results of the most recent search query. > > Is there a way to tell BaseX to abort running queries (by a specific > user) to privilege the most recent query (of this user)? Could this be > done with the Jobs module? Or is there a better way to implement such > a search? > > Best regards, > Sebastian > > -- > Sebastian Zimmer > sebastian.zimmer at uni-koeln.de <mailto:sebastian.zimmer at uni-koeln.de> > > Cologne Center for eHumanities <http://cceh.uni-koeln.de> > DH Center at the University of Cologne > @CCeHum <https://twitter.com/CCeHum> >
-- Sebastian Zimmer sebastian.zimmer at uni-koeln.de <mailto:sebastian.zimmer at uni-koeln.de> CCeH Logo <http://cceh.uni-koeln.de> Cologne Center for eHumanities <http://cceh.uni-koeln.de> DH Center at the University of Cologne Twitter Logo <https://twitter.com/CCeHum>@CCeHum <https://twitter.com/CCeHum>
MG
Maximilian Gärberin reply to Sebastian Zimmer, 7 Nov 2018, 14:327 Nov 2018 17:01 #
Hello, you can also add a helper on the client side to throttle the requests, e.g. with backbone/underscore [1] this looks like:
    searchBarKeyUp: _.throttle(function (e) {

      e.preventDefault();
      var $input = $(e.currentTarget);
      var val = $input.val();

      if (e.which == 13 || val.length > 2 || val == '') {

        this.searchValue = encodeURI(val);
        //
        this.setList();
      }
    },
    600)
[1] https://underscorejs.org/#throttle Br, Max Am Mi., 7. Nov. 2018 um 14:32 Uhr schrieb Sebastian Zimmer <sebastian.zimmer at uni-koeln.de>:
Quoted text · Sebastian Zimmer · 23 lines
> > Hi, > > I'm looking for a way to increase the *perceived* performance of the REST API. > > On my web page there's a results list that is updated automatically when the text content of an input field is changed. This means that on each keystroke by the user, a GET request to the REST API api is sent to obtain the new results list. > > One GET request takes about 800 ms, which is acceptable to me given the complexity of the query and the amount of data. > > The problem is that when the user types faster than the queries are executed, the app starts to respond very slowly, because there are now several requests pending. BaseX seems to execute all of them in parallel and it may well take up to 14 seconds until it returns the results of the most recent search query. > > Is there a way to tell BaseX to abort running queries (by a specific user) to privilege the most recent query (of this user)? Could this be done with the Jobs module? Or is there a better way to implement such a search? > > Best regards, > Sebastian > > -- > Sebastian Zimmer > sebastian.zimmer at uni-koeln.de > > Cologne Center for eHumanities > DH Center at the University of Cologne > @CCeHum

⚡Generated with XQuery