0

Currently, I'm working on a project like Uber. It means there are two apps: one for driver and one for customer.

The issue is: the driver need to update their location per 2 seconds. And the customer pull all the nearest drivers per 2 seconds for realtime. It cause bad performance in database query. I use cube & earthdistance extension of PostgreSQL for caculating the nearest.

Could anyone show me what's the best way to solve this issue? Thanks a lot!

Hoa Hoang
  • 1,212
  • 14
  • 20
  • 1
    If you are talking about cars and passengers you need a better solution than just comparing locations. With the PostGIS extension you can load a shapefile of road data and then do network analysis. Not much help if the nearest taxi is across the river or the highway. – Patrick Jul 21 '15 at 09:30
  • Lots and lots and lots of RAM. You're going to want to fit at least your indexes in RAM. Many CPUs and many fast disks. Also `UNLOGGED` tables for the realtime data. You'll lose it completely in a crash, but since only recent values are of interest that probably doesn't matter. – Craig Ringer Jul 22 '15 at 05:02

1 Answers1

0

You could use deepstream.io for realtime data submission, e.g. from Android

public void onLocationChanged(Location location) {
  // get the record
  Record record = client.record.getRecord( "driver/14" );
  // any kind of data path works
  record.set( "position.x", location.getLongitude() );
  //as well as any kind of serializable datatype
  record.set( "position.y", location.getLatitude() );
}

to JavaScript

// get the record
var driver = client.record.getRecord( 'driver/14' );

// subscribe to any changes within position
driver.subscribe( 'position', function( position ){
  updateMarker( position.x, position.y );
});

Combined with e.g. RethinkDBs geospacial queries which deepstream integrates with this might be a scalable solution.

Here's an example repo demonstrating this

wolframhempel
  • 1,094
  • 10
  • 12