Process multiple orders simultaneously and store in BD

Asked

Viewed 334 times

2

I’m dealing with a new problem because of some new challenges...

I developed a registration system and obviously in the future may have more than 100 registrations per day or even per hour or second. Thinking about it, I did a test on different pcs and did the registration at the same time using the two pcs, what happened was, the request of pc1 stored but the request of pc2 not.

I would like a help on how I can line up and then process orders if there are more than 1 at the same time...

Use jQuery to send the PHP form and the BD is mysql.

In PHP code is the normal code to insert data into a PDO DB

JS Code

    $.post("https://servidor/pasta/codigo.php", {
        nome: $nome,
        idade: $idade
}, function(dado){
      $("#msg").html("Inserido com sucesso");
})

Hugs and thanks in advance

  • Can you put here the PHP and JS you have? Unless you were able to submit the request in exactly the same millisecond, I don’t see why it could have missed one order and the other didn’t. You have to put more code...

  • @Sergio .. done... I do not believe it was in the same millisecond but the click on the two pcs, were...

  • Good also to inform what occurred in the requisition two, gave error ? Which ? Just not recorded ?

  • @Motta just didn’t record!

1 answer

1

What you said doesn’t make much sense, the server, depending on your setup, can "serve" hundreds/thousands of simultaneous requests. If you are using apache for example, the Directive MaxClients says the following:

The directive Maxclients arrow the amount of simultaneous requests that will be served. When this total is reached, the excess connection will enter a queue, the size of this queue can be set by the directive Listenbacklog.

The fact that two clients make a simultaneous request to the server is not a problem, in case this occurs, the server will create another process who will be responsible for the processing.

The question is, unless both scripts perform disk operations that require a lock (which is not your case), there is no timing technique that should be performed.

There are cases where it is necessary for transactional issues of the database to carry out special processing to prevent data from breaking integrity (which is also not the case following your example).

The problem in question is too broad, maybe it’s a problem in your test, who knows. The question I wanted to demonstrate in this text is almost with absolute certainty that it is not a synchronization problem unless your server is misconfigured.

  • I use Percona Server. And this test is being done remotely. By following your explanation, that is, if about 100 or more requests are made at the same time, the 100 or more requests were supposed to be entered into the database?

  • @C-lioGarcy in theory, yes, but there are configurations involved in both technologies, as I mentioned webserver must accept this amount of requests, just as mysql must accept, this specific has also a variable that performs this control called max_connections, but unlike apache if this number is exceeded an error will be returned. As you remarked there was no error so I believe that this limit has not been extrapolated.

  • in php code or jQuery has no way to manage this demand?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.