itinero / routing

The routing core of itinero.
Apache License 2.0
221 stars 69 forks source link

Calculate route very slow #213

Closed vincent-caron closed 6 years ago

vincent-caron commented 6 years ago

Hello,

I'm computing route from a central point and many points around it (between 200 and 300 points). I've loaded a routerdb created with the idp tool for pedestrian vehicle (from geofabrik france-latest.osm.pbf).

For most of the calculate it's very fast but suddenly it took a long time. I've put a stopwatch to track the time and here an example :

50,28602 / 2,79988 vers 50,27105 / 2,798653 00:00:00.0245858 50,28602 / 2,79988 vers 50,27176 / 2,792633 00:03:54.8091899 50,28602 / 2,79988 vers 50,27185 / 2,792245 00:00:00.0296471

note :

I've downloaded the src version and modified the basic sample to try it and i've the problem too.

I'll join the log file with all the points, if you want to give it a try.

i'm using itinero pre64 and itinero.osm pre64 with c#

Any help welcome because i'm in a dead end ....

Thanks log 1.txt

Pseudo code :

              var routerDb = new RouterDb();
                using (var stream = File.OpenRead(routerFile))
                {
                    routerDb = RouterDb.Deserialize(stream);
                }
                router = new Router(routerDb);

for each point 
{
   Result<RouterPoint> point2= router.TryResolve(profile, latitude, longitude);
                if (!pointTest.IsError)
                {
                    try
                    {
                        stopwatch.Start();
                        var chemin = router.Calculate(profile, point1, point2);
                        stopwatch.Stop();
                        logline = $"{point1.Latitude.ToString()} / {point1.Longitude.ToString()} vers {point2.Value.Latitude.ToString()} / {point2.Value.Longitude.ToString()} {stopwatch.Elapsed.ToString()}\n";
                        info = new UTF8Encoding(true).GetBytes(logline);
                        logstream.Write(info, 0, info.Length);

                        stopwatch.Reset();
                    }
                    catch (Exception)
                    {
                    }

                }
}
xivk commented 6 years ago

Thanks for the feedback, this is interesting. I'll try and have look soon, pretty crucial issue this.

This is also a good test to include in the functional testing. :+1:

vincent-caron commented 6 years ago

@xivk , i've downgraded to version 1.3.2 for routing and OSM and it works flawlessly ... May be something introduced in the 1.4.0 version ...

Can give a try to find when this has been broken ...

xivk commented 6 years ago

I was looking at this just now. I realized we are already testing for this scenario in the functional tests but we only test with a contracted graph. If I understand correctly this is happening after a long time and on random routes?

I just can't reproduce this issue. Are you running on .NET core or .NET framework?

vincent-caron commented 6 years ago

Yes, i'm not using contracted route, i've uses idp tool with pedestrian parameter for france.

I'm using .net framework. In fact, I've injected my code into your source of itinero and try from there. So, basically I'm using the technology you're using :)

xivk commented 6 years ago

Thanks for the feedback, I'm still trying to reproduce this. Two questions:

I would advise you to contract the graph, it will be a lot faster.

vincent-caron commented 6 years ago

Hi @xivk ,

Yes, it's always the same route that's slow Yes, i get the result after the 3mins.

All the others calculation (before and after) are very fast, as you can see in the file.

It seems like the garbage collector (or some sort of other process) is working like crazy ...

With the last version, the problem seems to be solved and i've not changed anything else in my code.

Bytheway, thanks for your investigations

xivk commented 6 years ago

Ok, thanks.

It's unlikely that this has something to do with garbage collection, probably something in Itinero. The only option I can think of is that sometimes Itinero doesn't handle routes that can't be found very gracefully. That has improved in the last version.

Closing this issue for now, feel free to reopen if you have this problem again.