Re: [OSRM-talk] Using OSRM linked into other code?

2014-11-15 Thread Stephen Woodbridge

Hi,

As a follow up to this, I wanted to report some progress.

Using Tools/simpleclient.cpp as a model, it was pretty easy to create a 
class that mimic that code for our limited needs. We connect via shared 
memory and we are able to get response times from viaroute requests of 
11-20 ms where they used to be about 500 ms.


And this is still passing json documents in the response so some of this 
time is spend encoding and decoding the json.


If you need to do something similar, I recommend looking at 
Tools/simpleclient.cpp and then wrapping those ideas into a class as you 
require.


Thank you everyone that offered ideas and suggests.

-Steve

On 11/7/2014 2:42 PM, Stephen Woodbridge wrote:

I'll answer a bunch of the reply's here:

1. we do pre-compute a distance matrix and use that already but if you
have a situation like:

o--t--uv->
|  ||
B  C|
|  ||
A--x--yz---D>

and you want the route A-B-C-D if you use a precomputed distance matrix
you get a path A-x-B-x-y-C-y-z-D (depending on where B and C are in
those segments (ie: the vehicle makes a u-turn at B and C) when we want
a route like A-x-B-t-u-C-y-z-D. OSRM will generate the later route if
you ask for the route A,B,C,D with via points. So a simple distance
matrix does not work well.

2. The performance issue is not with the C++, we get basically the same
performance using Perl (GET) or curl at the command line, or curl from C
or from c++.

3. I will look at the node-osrm code. I remember seeing that posted, but
had forgotten. Thanks for the reminder of that.

4. I am some what stuck on an older version of the source code because
I'm not in a position to upgrade my server OS and packages. :( So this
is somewhat problematic for me at the moment.

Anyway, lots of great ideas. I appreciate them all and will be digging
into them over the weekend.

Best regards,
   -Steve

On 11/7/2014 12:46 PM, John Firebaugh wrote:

Hi Steve,

Recent versions of osrm-backend build a library which you can link
against. See https://github.com/Project-OSRM/node-osrm/ for an example.

cheers,
John

On Fri, Nov 7, 2014 at 7:13 AM, Stephen Woodbridge
mailto:wood...@swoodbridge.com>> wrote:

Hi,

I seem to remember a while back that there was a discussion about
the possibility to embed the OSRM routing engine at the code level
rather than doing HTTP requests to a server.

I now find myself in a position that this would be desirable to do.
I have a small coverage area like a city, but I'm getting killed by
the overhead of formatting requests as strings, making a socket
connection to osrm-routed, parsing the responses, etc. Making local
requests my server this is taking 4-500 ms per request.

Basically, I'm doing viaroute requests with 2-100 via points. 99% of
the time all I need to know is the travel time.

Since I'm developing in C++, I thought it might be easy and much
faster to instantiate the routing engine and then have a simple
interface where I can pass a container of points and get back the
travel time for that route and/or the path coordinates. But I could
live without the coordinates if I had to.

Has anyone done this already? Can you share?

I have started digging through the source to see if I can do this,
but working my way in from osrm-routed or Tools/simpleclient.cpp the
code is very entangled with all the http request/response stuff that
I would ideally like to avoid. So far the most promising path looks
like using some variant of the simpleclient, but its not obvious if
or how to untangle all the json stuff and simply return a struct or
class to the caller without that. I spent most of yesterday, digging
through this and made a lot of progress just understanding
simpleclient and getting ti to compile and work and get it to actual
return results using a shared memory connection.

A little help in this direction would be appreciated.

Thanks,
   -Steve

_
OSRM-talk mailing list
OSRM-talk@openstreetmap.org 
https://lists.openstreetmap.__org/listinfo/osrm-talk





___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk




___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk



___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk


Re: [OSRM-talk] Using OSRM linked into other code?

2014-11-08 Thread Florian Lohoff
On Fri, Nov 07, 2014 at 10:13:20AM -0500, Stephen Woodbridge wrote:
> Hi,
> 
> I seem to remember a while back that there was a discussion about
> the possibility to embed the OSRM routing engine at the code level
> rather than doing HTTP requests to a server.
> 
> I now find myself in a position that this would be desirable to do.
> I have a small coverage area like a city, but I'm getting killed by
> the overhead of formatting requests as strings, making a socket
> connection to osrm-routed, parsing the responses, etc. Making local
> requests my server this is taking 4-500 ms per request.

That must be some other problem. I have seen something like 100+ Requests/s
with perl on a localhost osrm. It was basically that fast that i had problems
with the number of TCP sessions stuck in TIME_WAIT2 so i had to tune the tcp
timers. The limiting factor then was my perl client code parsing the json stuff
and dumping geometries to a postgis. (Converting the JSON to WKT Linestring 
etc).
This was on a quad-core with 16Gigabytes and a German extract. I did not let
OSRM compress the geometry as bandwidth is not a problem on localhost
e.g. (compression=false)

Flo
-- 
Florian Lohoff f...@zz.de


signature.asc
Description: Digital signature
___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk


Re: [OSRM-talk] Using OSRM linked into other code?

2014-11-07 Thread Antonio Moratilla OcaƱa
Hello

A year ago I was in the same situation, but using Java.

The found the problem was not about OSRM server but connection overhead in
my own program. Creating a new http connection for each request was simply
not an option: i could manage to get about 20 request at max. I tried to
use external todos like wget and curl, but that didn't worked at all.

The solution in my case was to use apache httpclient library in concurrent
mode, with resources for about 12 concurrent conections in 8 concurrent
threads.

With that configuration I managed to pass from as much as 20 request per
second to more than 900 request per second At that speed, OSRM was
using about 100% CPU time, so it worked full speed... :)

Maybe this could help you... If you need code let me know

Kind regards

El viernes, 7 de noviembre de 2014, Stephen Woodbridge <
wood...@swoodbridge.com> escribiĆ³:

> I'll answer a bunch of the reply's here:
>
> 1. we do pre-compute a distance matrix and use that already but if you
> have a situation like:
>
> o--t--uv->
>|  ||
>B  C|
>|  ||
> A--x--yz---D>
>
> and you want the route A-B-C-D if you use a precomputed distance matrix
> you get a path A-x-B-x-y-C-y-z-D (depending on where B and C are in those
> segments (ie: the vehicle makes a u-turn at B and C) when we want a route
> like A-x-B-t-u-C-y-z-D. OSRM will generate the later route if you ask for
> the route A,B,C,D with via points. So a simple distance matrix does not
> work well.
>
> 2. The performance issue is not with the C++, we get basically the same
> performance using Perl (GET) or curl at the command line, or curl from C or
> from c++.
>
> 3. I will look at the node-osrm code. I remember seeing that posted, but
> had forgotten. Thanks for the reminder of that.
>
> 4. I am some what stuck on an older version of the source code because I'm
> not in a position to upgrade my server OS and packages. :( So this is
> somewhat problematic for me at the moment.
>
> Anyway, lots of great ideas. I appreciate them all and will be digging
> into them over the weekend.
>
> Best regards,
>   -Steve
>
> On 11/7/2014 12:46 PM, John Firebaugh wrote:
>
>> Hi Steve,
>>
>> Recent versions of osrm-backend build a library which you can link
>> against. See https://github.com/Project-OSRM/node-osrm/ for an example.
>>
>> cheers,
>> John
>>
>> On Fri, Nov 7, 2014 at 7:13 AM, Stephen Woodbridge
>> mailto:wood...@swoodbridge.com>> wrote:
>>
>> Hi,
>>
>> I seem to remember a while back that there was a discussion about
>> the possibility to embed the OSRM routing engine at the code level
>> rather than doing HTTP requests to a server.
>>
>> I now find myself in a position that this would be desirable to do.
>> I have a small coverage area like a city, but I'm getting killed by
>> the overhead of formatting requests as strings, making a socket
>> connection to osrm-routed, parsing the responses, etc. Making local
>> requests my server this is taking 4-500 ms per request.
>>
>> Basically, I'm doing viaroute requests with 2-100 via points. 99% of
>> the time all I need to know is the travel time.
>>
>> Since I'm developing in C++, I thought it might be easy and much
>> faster to instantiate the routing engine and then have a simple
>> interface where I can pass a container of points and get back the
>> travel time for that route and/or the path coordinates. But I could
>> live without the coordinates if I had to.
>>
>> Has anyone done this already? Can you share?
>>
>> I have started digging through the source to see if I can do this,
>> but working my way in from osrm-routed or Tools/simpleclient.cpp the
>> code is very entangled with all the http request/response stuff that
>> I would ideally like to avoid. So far the most promising path looks
>> like using some variant of the simpleclient, but its not obvious if
>> or how to untangle all the json stuff and simply return a struct or
>> class to the caller without that. I spent most of yesterday, digging
>> through this and made a lot of progress just understanding
>> simpleclient and getting ti to compile and work and get it to actual
>> return results using a shared memory connection.
>>
>> A little help in this direction would be appreciated.
>>
>> Thanks,
>>-Steve
>>
>> _
>> OSRM-talk mailing list
>> OSRM-talk@openstreetmap.org 
>> https://lists.openstreetmap.__org/listinfo/osrm-talk
>> 
>>
>>
>>
>>
>> ___
>> OSRM-talk mailing list
>> OSRM-talk@openstreetmap.org
>> https://lists.openstreetmap.org/listinfo/osrm-talk
>>
>>
>
> __

Re: [OSRM-talk] Using OSRM linked into other code?

2014-11-07 Thread Stephen Woodbridge

I'll answer a bunch of the reply's here:

1. we do pre-compute a distance matrix and use that already but if you 
have a situation like:


o--t--uv->
   |  ||
   B  C|
   |  ||
A--x--yz---D>

and you want the route A-B-C-D if you use a precomputed distance matrix 
you get a path A-x-B-x-y-C-y-z-D (depending on where B and C are in 
those segments (ie: the vehicle makes a u-turn at B and C) when we want 
a route like A-x-B-t-u-C-y-z-D. OSRM will generate the later route if 
you ask for the route A,B,C,D with via points. So a simple distance 
matrix does not work well.


2. The performance issue is not with the C++, we get basically the same 
performance using Perl (GET) or curl at the command line, or curl from C 
or from c++.


3. I will look at the node-osrm code. I remember seeing that posted, but 
had forgotten. Thanks for the reminder of that.


4. I am some what stuck on an older version of the source code because 
I'm not in a position to upgrade my server OS and packages. :( So this 
is somewhat problematic for me at the moment.


Anyway, lots of great ideas. I appreciate them all and will be digging 
into them over the weekend.


Best regards,
  -Steve

On 11/7/2014 12:46 PM, John Firebaugh wrote:

Hi Steve,

Recent versions of osrm-backend build a library which you can link
against. See https://github.com/Project-OSRM/node-osrm/ for an example.

cheers,
John

On Fri, Nov 7, 2014 at 7:13 AM, Stephen Woodbridge
mailto:wood...@swoodbridge.com>> wrote:

Hi,

I seem to remember a while back that there was a discussion about
the possibility to embed the OSRM routing engine at the code level
rather than doing HTTP requests to a server.

I now find myself in a position that this would be desirable to do.
I have a small coverage area like a city, but I'm getting killed by
the overhead of formatting requests as strings, making a socket
connection to osrm-routed, parsing the responses, etc. Making local
requests my server this is taking 4-500 ms per request.

Basically, I'm doing viaroute requests with 2-100 via points. 99% of
the time all I need to know is the travel time.

Since I'm developing in C++, I thought it might be easy and much
faster to instantiate the routing engine and then have a simple
interface where I can pass a container of points and get back the
travel time for that route and/or the path coordinates. But I could
live without the coordinates if I had to.

Has anyone done this already? Can you share?

I have started digging through the source to see if I can do this,
but working my way in from osrm-routed or Tools/simpleclient.cpp the
code is very entangled with all the http request/response stuff that
I would ideally like to avoid. So far the most promising path looks
like using some variant of the simpleclient, but its not obvious if
or how to untangle all the json stuff and simply return a struct or
class to the caller without that. I spent most of yesterday, digging
through this and made a lot of progress just understanding
simpleclient and getting ti to compile and work and get it to actual
return results using a shared memory connection.

A little help in this direction would be appreciated.

Thanks,
   -Steve

_
OSRM-talk mailing list
OSRM-talk@openstreetmap.org 
https://lists.openstreetmap.__org/listinfo/osrm-talk





___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk




___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk


Re: [OSRM-talk] Using OSRM linked into other code?

2014-11-07 Thread Jacob Roope
Stephen and Per,

Have you considered precomputing your matrix. It is front end intensive but
I currently store the entirety of North America in my database for analysis
and it is much quicker than running all the HTTP requests as needed.

Also, there is a distance matrix feature in the latest builds that does
drive time if that is all you need.
https://github.com/Project-OSRM/osrm-backend/wiki/Server-api#distance-tables

If those don't solve your problem I can share my pre-building code with
you.

Jacob




On Fri, Nov 7, 2014 at 12:17 PM, Stephen Woodbridge  wrote:

> Per,
>
> Thank your for responding. We are also doing the HTTP requests, but the
> performance is killing us. So just a quick update on what I have found out
> so far:
>
> time GET 'http://localhost:5000/viaroute?...'
>
> takes about 500 ms on my system.
>
> time ./simpleclient --sharedmemory
>
> takes about 44 ms with all the default options in the code turned on
> takes about 22 ms with all the options turned off
>
> And these numbers are based on still returning json output and parsing
> that.
>
> So if it were possible to turn simpleclient into object with a few simple
> options we could get something close to the performance improvement above.
>
> And if we can untangle the json encoding and parse and just pass back raw
> data we would probably see some additional improvement over those numbers.
>
> This seems like a worthy path to follow, hence my request for some help or
> pointers untangling json encoding and parsing.
>
> Thanks,
>   -Steve
>
> On 11/7/2014 10:41 AM, Per Lindberg wrote:
>
>> I guess that was me. We also would love to have a single
>> sharable object file (.dll and .so) with a documented API.
>> All we need is travel time from A to B. We currently do
>> gazillions of HTTP calls to a separate process, so a more
>> direct call would be wonderful.
>>
>> Keep me posted if you see any progress in this.
>>
>> Cheers,
>> Per Lindberg
>> Facility labs
>>
>>
>>
>>
>> On 2014-11-07 16:13, Stephen Woodbridge wrote:
>>
>>> Hi,
>>>
>>> I seem to remember a while back that there was a discussion about the
>>> possibility to embed the OSRM routing engine at the code level rather
>>> than doing HTTP requests to a server.
>>>
>>> I now find myself in a position that this would be desirable to do. I
>>> have a small coverage area like a city, but I'm getting killed by the
>>> overhead of formatting requests as strings, making a socket connection
>>> to osrm-routed, parsing the responses, etc. Making local requests my
>>> server this is taking 4-500 ms per request.
>>>
>>> Basically, I'm doing viaroute requests with 2-100 via points. 99% of the
>>> time all I need to know is the travel time.
>>>
>>> Since I'm developing in C++, I thought it might be easy and much faster
>>> to instantiate the routing engine and then have a simple interface where
>>> I can pass a container of points and get back the travel time for that
>>> route and/or the path coordinates. But I could live without the
>>> coordinates if I had to.
>>>
>>> Has anyone done this already? Can you share?
>>>
>>> I have started digging through the source to see if I can do this, but
>>> working my way in from osrm-routed or Tools/simpleclient.cpp the code is
>>> very entangled with all the http request/response stuff that I would
>>> ideally like to avoid. So far the most promising path looks like using
>>> some variant of the simpleclient, but its not obvious if or how to
>>> untangle all the json stuff and simply return a struct or class to the
>>> caller without that. I spent most of yesterday, digging through this and
>>> made a lot of progress just understanding simpleclient and getting ti to
>>> compile and work and get it to actual return results using a shared
>>> memory connection.
>>>
>>> A little help in this direction would be appreciated.
>>>
>>> Thanks,
>>>-Steve
>>>
>>> ___
>>> OSRM-talk mailing list
>>> OSRM-talk@openstreetmap.org
>>> https://lists.openstreetmap.org/listinfo/osrm-talk
>>>
>>
>>
>
> ___
> OSRM-talk mailing list
> OSRM-talk@openstreetmap.org
> https://lists.openstreetmap.org/listinfo/osrm-talk
>
___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk


Re: [OSRM-talk] Using OSRM linked into other code?

2014-11-07 Thread John Firebaugh
Hi Steve,

Recent versions of osrm-backend build a library which you can link against.
See https://github.com/Project-OSRM/node-osrm/ for an example.

cheers,
John

On Fri, Nov 7, 2014 at 7:13 AM, Stephen Woodbridge 
wrote:

> Hi,
>
> I seem to remember a while back that there was a discussion about the
> possibility to embed the OSRM routing engine at the code level rather than
> doing HTTP requests to a server.
>
> I now find myself in a position that this would be desirable to do. I have
> a small coverage area like a city, but I'm getting killed by the overhead
> of formatting requests as strings, making a socket connection to
> osrm-routed, parsing the responses, etc. Making local requests my server
> this is taking 4-500 ms per request.
>
> Basically, I'm doing viaroute requests with 2-100 via points. 99% of the
> time all I need to know is the travel time.
>
> Since I'm developing in C++, I thought it might be easy and much faster to
> instantiate the routing engine and then have a simple interface where I can
> pass a container of points and get back the travel time for that route
> and/or the path coordinates. But I could live without the coordinates if I
> had to.
>
> Has anyone done this already? Can you share?
>
> I have started digging through the source to see if I can do this, but
> working my way in from osrm-routed or Tools/simpleclient.cpp the code is
> very entangled with all the http request/response stuff that I would
> ideally like to avoid. So far the most promising path looks like using some
> variant of the simpleclient, but its not obvious if or how to untangle all
> the json stuff and simply return a struct or class to the caller without
> that. I spent most of yesterday, digging through this and made a lot of
> progress just understanding simpleclient and getting ti to compile and work
> and get it to actual return results using a shared memory connection.
>
> A little help in this direction would be appreciated.
>
> Thanks,
>   -Steve
>
> ___
> OSRM-talk mailing list
> OSRM-talk@openstreetmap.org
> https://lists.openstreetmap.org/listinfo/osrm-talk
>
___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk


Re: [OSRM-talk] Using OSRM linked into other code?

2014-11-07 Thread Stephen Woodbridge

Per,

Thank your for responding. We are also doing the HTTP requests, but the 
performance is killing us. So just a quick update on what I have found 
out so far:


time GET 'http://localhost:5000/viaroute?...'

takes about 500 ms on my system.

time ./simpleclient --sharedmemory

takes about 44 ms with all the default options in the code turned on
takes about 22 ms with all the options turned off

And these numbers are based on still returning json output and parsing that.

So if it were possible to turn simpleclient into object with a few 
simple options we could get something close to the performance 
improvement above.


And if we can untangle the json encoding and parse and just pass back 
raw data we would probably see some additional improvement over those 
numbers.


This seems like a worthy path to follow, hence my request for some help 
or pointers untangling json encoding and parsing.


Thanks,
  -Steve

On 11/7/2014 10:41 AM, Per Lindberg wrote:

I guess that was me. We also would love to have a single
sharable object file (.dll and .so) with a documented API.
All we need is travel time from A to B. We currently do
gazillions of HTTP calls to a separate process, so a more
direct call would be wonderful.

Keep me posted if you see any progress in this.

Cheers,
Per Lindberg
Facility labs



On 2014-11-07 16:13, Stephen Woodbridge wrote:

Hi,

I seem to remember a while back that there was a discussion about the
possibility to embed the OSRM routing engine at the code level rather
than doing HTTP requests to a server.

I now find myself in a position that this would be desirable to do. I
have a small coverage area like a city, but I'm getting killed by the
overhead of formatting requests as strings, making a socket connection
to osrm-routed, parsing the responses, etc. Making local requests my
server this is taking 4-500 ms per request.

Basically, I'm doing viaroute requests with 2-100 via points. 99% of the
time all I need to know is the travel time.

Since I'm developing in C++, I thought it might be easy and much faster
to instantiate the routing engine and then have a simple interface where
I can pass a container of points and get back the travel time for that
route and/or the path coordinates. But I could live without the
coordinates if I had to.

Has anyone done this already? Can you share?

I have started digging through the source to see if I can do this, but
working my way in from osrm-routed or Tools/simpleclient.cpp the code is
very entangled with all the http request/response stuff that I would
ideally like to avoid. So far the most promising path looks like using
some variant of the simpleclient, but its not obvious if or how to
untangle all the json stuff and simply return a struct or class to the
caller without that. I spent most of yesterday, digging through this and
made a lot of progress just understanding simpleclient and getting ti to
compile and work and get it to actual return results using a shared
memory connection.

A little help in this direction would be appreciated.

Thanks,
   -Steve

___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk





___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk


[OSRM-talk] Using OSRM linked into other code?

2014-11-07 Thread Stephen Woodbridge

Hi,

I seem to remember a while back that there was a discussion about the 
possibility to embed the OSRM routing engine at the code level rather 
than doing HTTP requests to a server.


I now find myself in a position that this would be desirable to do. I 
have a small coverage area like a city, but I'm getting killed by the 
overhead of formatting requests as strings, making a socket connection 
to osrm-routed, parsing the responses, etc. Making local requests my 
server this is taking 4-500 ms per request.


Basically, I'm doing viaroute requests with 2-100 via points. 99% of the 
time all I need to know is the travel time.


Since I'm developing in C++, I thought it might be easy and much faster 
to instantiate the routing engine and then have a simple interface where 
I can pass a container of points and get back the travel time for that 
route and/or the path coordinates. But I could live without the 
coordinates if I had to.


Has anyone done this already? Can you share?

I have started digging through the source to see if I can do this, but 
working my way in from osrm-routed or Tools/simpleclient.cpp the code is 
very entangled with all the http request/response stuff that I would 
ideally like to avoid. So far the most promising path looks like using 
some variant of the simpleclient, but its not obvious if or how to 
untangle all the json stuff and simply return a struct or class to the 
caller without that. I spent most of yesterday, digging through this and 
made a lot of progress just understanding simpleclient and getting ti to 
compile and work and get it to actual return results using a shared 
memory connection.


A little help in this direction would be appreciated.

Thanks,
  -Steve

___
OSRM-talk mailing list
OSRM-talk@openstreetmap.org
https://lists.openstreetmap.org/listinfo/osrm-talk