0

I am trying to build a Tracking System where in an android app sends GPS data to a web server using Laravel. I have read tutorials on how to do realtime apps but as how I have understand, most of the guides only receives data in realtime. I haven't seen yet examples of sending data like every second or so.

I guess its not a good practice to POST data every second to a web server specially when you already have a thousand users. I hope anyone could suggest how or what should I do to get this approach?

Also, as much as possible I would only like to use Laravel without any NodeJS server.

Jhon Andrew
  • 188
  • 3
  • 14
  • Depends on how many users, etc. Nginx is pretty good at handling tons of concurrent connections, but really it's too hard to know given there are so many variables. You may consider using a stress tester to see how many concurrent connections you can have before you experience server degradation. – Ohgodwhy Aug 11 '17 at 02:25
  • I think you can use fire base and you can connect from frontend instead of using laravel. Go though it once https://firebase.google.com/docs/database/ it may be helpful to you. – Mr.Throg Aug 11 '17 at 04:37
  • @VenkatLokeswar thanks for the suggestion. I would also choose Firebase if I can but I am required to use MySQL for its database that's why I decided to make it in Laravel. – Jhon Andrew Aug 11 '17 at 05:25

2 Answers2

1

Do sending quickly

First you should estimate server capacity. As of fpm, if you have 32 php processes and every post request handles by a server within 0.01sec, capacity can be roughly estimated asN = 32 / 0.01 = 3200 requests per second.

So just do handling fast. If your request handles for 0.1sec, it is too slow to have a lot of clients on a single server. Enable opcache, it can decrease time 5x. Inserting data to mysql is a slow operation, so you probably need to work it out to make it faster. Say, add it to a fast cache (redis\memcached) and when cache already contains 1000 elements or cache is created more than 0.5 seconds ago, move it to a database as a single insert query.

Do sending random

Most of smartphones may have correct time. So it can lead to a thousand of simultaneous requests when next second starts. So, first 0.01sec server will handle 1000 requests, next 0.99sec it will sleep. Insert at mobile code a random delay 0-0.9sec which is fixed for every device and defined at first install or request. It will load server uniformly.

shukshin.ivan
  • 11,075
  • 4
  • 53
  • 69
0

There's at least 2 really important things you should consider:

  • Client's internet consumption
  • Server capacity

If you got a thousand users, every second would mean a lot of requests for you server to handle.

You should consider using some pushing techniques, like described in this @Dipin answer:

And when it comes to the server, you should consider using a queue system to handle those jobs. Like described in this article There's probably some package providing the integration to use Firebase or GCM to handle that for you.

Good luck, hope it helps o/

Renato Gomes
  • 126
  • 4