I'll try to be as thorough as possible.
I have an application written in PHP using the codeigniter framework.
On a few, but one particular page I have a lot of information to show therefore thought it a good idea to split it all into multiple Ajax calls. It's been like this for at least the last 2 years yet recently my customers are complaining of speed issues.
I've tested the page and 6/10 times it loads with out issue.
The page has 6 ajax calls as shown in the image, most taking less than 500ms to run.
However, on roughly 4/10 page reloads it will hang causing at least 2 of the ajax calls to take way over 5 seconds to complete, even as much as 20 seconds sometimes.
Here's a snippet of code:
$('#table_booking_details').dataTable({
"autoWidth": false,
"responsive" : {
"details": false,
},
"ajax": {
"url" : "/admin/booking/dt_get_rental_date_times/",
"type" : "POST",
"data" : {
"rental_index" : $('#rental_index').val()
}
},
"serverSide" : true,
"processing" : true,
});
public function dt_get_rental_date_times()
{
$rental_index = $this->input->post('rental_index');
$search = $this->input->post('search');
$search_param = $search['value'];
$sort = $this->input->post('order');
$sort_column_index = $sort['0']['column'];
$sort_direction = $sort['0']['dir'];
$length = $this->input->post('length');
$start = $this->input->post('start');
$sort_column_array = array("0" => "collection_date_time", "1" => "return_date_time", "2" => "vehicle_registration", "3" => "(return_date_time - collection_date_time)", "4" => "rental_date_time_cost");
$sort_column = $sort_column_array[$sort_column_index];
$rental_date_times_result = $this->rentals_model->dt_get_rental_date_times($length, $start, $sort_column, $sort_direction, $search_param, $rental_index);
$rental_date_times = $rental_date_times_result['rows'];
$rental_date_times_count = $rental_date_times_result['num_rows'];
$data['recordsTotal'] = $rental_date_times_count;
$data['recordsFiltered'] = $rental_date_times_count;
$results = array();
$i = 0;
foreach ($rental_date_times as $rent)
{
$days = ceil(($rent->return_date_time - $rent->collection_date_time) / 60 / 60 / 24);
$actions = '';
if($rent->swapover == 1)
{
$actions = 'Yes';
}
else
{
$actions = 'No';
}
$results[] = array(
"DT_RowId" => "rentalperiod_" . $rent->rental_date_time_index,
"DT_RowClass" => 'linkable_row',
"0" => timestamp_to_date_time($rent->collection_date_time),
"1" => timestamp_to_date_time($rent->return_date_time),
"2" => $rent->vehicle_registration,
"3" => $days,
"4" => $rent->rental_date_time_cost,
"5" => $actions
);
}
$data['data'] = $results;
echo json_encode($data);
}
Firstly is it likely this is a new thing that people are just starting to notice, seems a little strange it would just randomly start happening.
Any suggestions what I can do to improve it without moving everything back to old school php with page reloads.
Thanks