📜 ⬆️ ⬇️

AJAX: stability and reliability problems with heavy server load

The last couple of months I have been writing a small Ajax application.

In short, such a simplified browser-based Excel is a filter on top, a data label on the bottom. The user selects in the filter what he wants to edit, the data is loaded into the plate from the bottom, the user can edit it, after changing the data, they are sent to the server, processed there, written to the database, the server generates new data, graphs, sends data back, the graphs are displayed separately in iFrame. Before me, this application was not ayaksovym, but was based on the usual forms, and the user had to wait for a new page load after each filter or data change (since the data in the cells depended on other cells, they had to do a recalculation after each change), and I was instructed to redo it all under Ajax. I am not a javascript programmer, I am from the world of Delphi / Builder, where the whole interface is drawn without problems for half an hour, and then the logic is written. I had to learn a lot on the go, almost everything had to be written by myself (manually drawing controls and describing events in javascript, simultaneously struggling with incompatibility or different reactions of different browsers to the same code - brrrr, you don’t want the enemy).

From the beginning, everything was fine, while I was working with the program, as an ajax programmer, and our php programmer, who implemented server logic (everything is much more complicated than in a browser — large amounts of computation, communication with different data sources).
And so, we debugged all the logic and loaded real data, and the testers were connected to the project, and the customer also started testing. And it was here that the terrible thing began ...

The load on the server has increased many times, the processor is often 100% loaded, especially if several users work at the topmost level, when, after changing a single value in the plate, it is necessary to recalculate at all levels below and record changes to the database (yes, not perfect planning and design). ) - but this did not concern me much, I am responsible only for the client interface.
')
I was concerned that the AYAX began to fail - then the connection is interrupted, then error 504, then the data will come broken and incorrectly collected by eval () - th (I use the JSON format, I chose for ease of use: json_encode ($ data) on the server and var data = eval ("(" + json_string + ")") in the browser). Moreover, irregular errors are difficult to track. Then a few Ajax requests sent in a row will return in the wrong order. Or the user changes five values ​​in a row in a plate, everything except the fourth is processed by the system - the request has disappeared along the way, and of course, the customer has never been pleased with this.

So there was a need for some kind of Connection Pool, which would manage all requests (I create my own AJAX object for each request and process it completely independently of others - with low load and a small amount of data everything worked very quickly and without failures), would distinguish the types of requests (data changes - in strict sequence and depending on the results of previous requests, filter changes - no more than once at a time, etc., it would also be nice to block the input before processing important requests), send requests to page I would go through the sequence and process them in the order they were sent, if corrective communication errors occurred, I would try again, and in the case of uncorrectable errors I would cancel requests, etc.

I think many have already encountered a similar problem and somehow solved it. I'm not even interested in the finished code, but the algorithm, the description of the technology. Well, any advice experienced Ajax programmers.

Please answer only on the merits of the question.

Thanks for attention.

Source: https://habr.com/ru/post/16524/


All Articles