We have a Laravel web app hosted on AWS ec2 instance. Normally the cpu utilization is at 10 to 20%. We recieve some network request to store request in order to store coordinates to track user. Controller method is as below
DB::beginTransaction();
Position::updateOrCreate(['staff_id' => $request->staff_id, 'date' => date('Y-m-d'), 'longitude' => $request->longitude, 'latitude' => $request->latitude],['sort'=>$request->sort,'staff_id' => $request->staff_id, 'date' => date('Y-m-d'), 'longitude' => $request->longitude, 'latitude' => $request->latitude]);
DB::commit();
return response()->json(['message' => 'Success']);
And this method always takes 6MB of memory as we see in telescope.
Secondly, We need to store coordiates in local storage on mobile app. so if user does not have internet connection we can track which route did the user took to complete delivery. Sometimes for longer routes the stores coordinates become in count 10k. Now all those 10k rqeuest are getting sent to server every single second. Which causes server to stop every few minutes.
So I have two questions
1. What is causing 6MB of memory usage in method mentioned above?
2. If there is a way we can keep all the records stored somewhere such that server does not have too many network requests (I'm not sure if I am clear or not but my aim is to store all data but not causing too many network requests)
Thanks,