0

This behavior was not present all the time, just come from nothing about a month ago and then disappeared suddenly. The problem is that I can't identify what happened. I have no server debug tool because only take place in production. Roughly 100 ajax request are triggered at the same time using some loop like :

let url = "example.com/";

var methods = ["method1", "method2", "method3", "method4"]; //Roughly 100   

$.each(methods, function(index, value) {
  $.ajax({
    url: url + value,
    method: "POST",
    data: { params: "whatever", otherParams: "whatever" }
  }).done(function(data) {
    console.log(data);
  });
});

In server side (apache+php) there are selects, updates and inserts in a relational database. Each request performs an individual thread since apache is hearing.

When I see the network console, all requests starts at the same time (roughly), but here is the problem. The response happen one after the other finish. If request 1 starts at 0 and spend 5 seconds, request 2 starts at 5, and request 3 starts when request 2 was finished. All browser have the same behavior.

The best logic explanation I thought, is that database is blocking some table when performs an update or insert. Some tables are huge and without indexes could spend too much time. Well, staging environment points to the same database and works perfectly asynchronously. So what is going on? It is possible that php or Apache could be stucked in this way for some reason? I thought other crazy idea that is some writing problems with log files in the OS (debian) but I have no idea how that works. So I would be glad if anyone could give me any suggestion. Maybe I could reproduce the problem in a controlled environment and do something to prevent this can happen again.

Some additional information, the API have two clients one in angular the other in javascript+php. It's exactly the same behavior with both clients.

Emeeus
  • 5,072
  • 2
  • 25
  • 37
  • If you are able to reproduce it on production, you probably would monitor your web and database servers. Without any monitoring it is really hard to find what it is. But as you said it _may_ be because of a table lock. It's not because of only one query if your server is slow, but because of a set of queries, so it's hard to reproduce. Try to log the process list of your server and you'll see if a table is really used and needs an index or something similar. – Anthony May 14 '18 at 14:20
  • Do you use any frameworks on backend? May be Symfony? – mochalygin May 14 '18 at 14:27
  • @AnthonyB I can't reproduce it, because I don't know what to do. I should log every time spend in each process, I don't see possible but maybe it's the only way. – Emeeus May 14 '18 at 14:36
  • @mochalygin no framework. – Emeeus May 14 '18 at 14:36
  • It's hard to fix something that we can't reproduce. In MySQL you can log the queries that take more than X seconds, it's a configuration in my.cnf. It could help you to log the queries that take too much time. – Anthony May 14 '18 at 14:52
  • 1
    Have a look at this: https://stackoverflow.com/questions/15686572/two-simultaneous-ajax-requests-wont-run-in-parallel?noredirect=1&lq=1 – xyzale May 14 '18 at 14:55
  • @xyzale It's interesting the Darien reply. I have no problem with session (one client have no session at all). Unfortunately I'm not working with xdebug or zend, but it's an interesting point of view. – Emeeus May 14 '18 at 15:21

0 Answers0