How to handle large number of api requests in laravel to reduce the cpu utilization?

Viewed 27

We are using the mobile app to save the coordinates of users when they are driving. location get stored after every 100 meters. when there are multiple users and they are driving at high speed they sent a lot of requests on the server which uses 100% of the CPU. every request use 6Mb of memory. enter image description here

I tried to apply the throttle limit of API routes but still, it uses that memory.

There is nothing much in controller function just a db query

 public function savePosition(Request $request)
    {
        
        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' => 'Posición guardada correctamente']);
    }

I am using AWS ec2 instance for hosting

0 Answers
Related