Can ajax calls overload a server?

2

I am developing an application that has some elements of the database, so I have to make ajax calls for each component, I have about 50 tables which have brands, models, product types, etc.

It is so to do it in a SPA I call all those elements via ajax to avoid having to reload the page. Only for brands, models and product types, there would be 150 calls ajax, the calls I make them like this:

$.ajax({
  type: "POST",
  dataType: 'json',
  data: { 'tipo': 'congelador'},
  url: "<?php echo site_url();?>"+"/marca/obtenerMarcasbytipo",
  success : function(data) {
    //console.log(data);
    $.each(data, function(key, val) {
      //console.log(key+" "+val.id_marca +" "+val.nombre_marca);
      $("#marca_congelador").append('<option value="'+ val.id_marca + '">' + val.nombre_marca + '</option>');
    });

  }
});

My question is:

Can all these calls overload the server, and if so, should you separate all these calls to avoid it?

    
asked by Juan Pinzón 16.09.2016 в 23:06
source

2 answers

3

For the server that attends the requests, it is not 100% relevant if the call comes by Ajax, by Browser, by curl or other. At the end of the day, the call is a request-response cycle that must be attended to. Many requests to the server will overload it.

I recommend that you have the following points to consider in your backend application:

  • Reduce the "chattiness". That is, the number of request-response cycles generated to the server is the lowest possible. It is better to provide the information in 1 request than to provide the same information in 10 requests.
  • Compress the server response. In this way, you reduce the communication latency time between the client and the server. You can use the header Content-Encoding: gzip , for example. More info: Http compression .
  • The protocol matters . If possible, use HTTP 2 instead of HTTP 1.x, since HTTP 2 brings multiple improvements for the interaction with the backend server. You can see a list of servers with HTTP 2 support here: link
  • answered by 16.09.2016 в 23:26
    3
      

    Can all these calls overload the server?

    Yes, any type of request , whether direct or by ajax , the server has to process.

      

    and if so, should I separate all these calls to avoid it?

    Yes, and the first load only calls those that are essential for your use cases, I doubt very much that you have to call 150 for a use case.

    Perform stress tests and check how much performance you have, a good recommended tool: Apache JMeter link

    Play with the caché to avoid overloading the server at the level of $.ajax and I suggest you store some information using the APIs of HTML5 : localStorage , SessionStorage on the side of the client.

    LocalStorage is accepted by 92.96% of browsers according to: link

    SessionStorage also with 92.96% according to: link

        
    answered by 16.09.2016 в 23:49