Delay in massive processing of ajax Codeigniter

Asked

Viewed 147 times

0

My code imports data from one database to another. To avoid server overload, I am importing 100 out of 100 records into each ajax. I noticed that in the first requisitions, it takes about 40ms, however, as sending more requisitions, the return time grows a lot for 80ms, 100ms up to 400ms. I am using the mysql connection of the Codeigniter framework; I am also using, in a single part of the code, a php mysqli connection, and closing it in every request. I do not understand why as increasing the amount of requests takes longer. Is the Codeigniter connection not closing as expected?

  • 1

    Complicated to say something, the ideal serial run a profile to try to find the bottleneck and then try to solve the problem. Indexes can make instructions like Insert or update slower. As this import is done, you could put the code?

  • The import assembles a SELECT query based on some information I pass, so far I have only Select queries and there is no reason to increase the return time. Then I put this Select in an INSERT IGNORE and close the connection. The code is too big, there is no way to pass here. I do not understand why the returns are more and more time consuming if I do the same queries (only by changing the select LIMIT)

1 answer

0

Vinicius, you are using AJAX to perform this import because it must be triggered/soldered by the user only?

If possible, you can set up a cron task and run it automatically at a specific time.

In the cron task you can have a routine that would be the following:

Make a select by getting the data to be imported, one table at a time, store this data in variables (they will be an array or object) and then use the Codeigniter batch process.

$this->db->insert_batch()

http://www.codeigniter.com/user_guide/database/query_builder.html?highlight=insert_batch#CI_DB_query_builder::insert_batch

Browser other questions tagged

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