itinero / routing

The routing core of itinero.
Apache License 2.0
220 stars 70 forks source link

Method RouterDb.AddContracted took 3h and throws OutOfMemory exception #316

Open Georgy-Losenkov opened 4 years ago

Georgy-Losenkov commented 4 years ago

I am using nuget packages version 1.5.0. Below is code that I used. Similar code on same machine using Osm.Routing.dll (v0.4.5.143) finished in 5 minute:

        static void PrepareDatabase()
        {
            var routerDb = new RouterDb();
            Console.WriteLine(DateTime.Now);
            Console.WriteLine("Loading from pbf");
            // file downloaded from "https://download.geofabrik.de/russia-latest.osm.pbf"
            using (var stream = new FileStream(@"C:\Maps\russia-latest.osm.pbf", FileMode.Open, FileAccess.Read, FileShare.Read, 1048576))
            {
                routerDb.LoadOsmData(stream, false, Vehicle.Car);
            }

            Console.WriteLine(DateTime.Now);
            Console.WriteLine("Adding contracted Car");
            routerDb.AddContracted(Vehicle.Car.Shortest()); // <-- OutOfMemory here (9GB memory)

            Console.WriteLine(DateTime.Now);
            Console.WriteLine("Saving database to memory");
            using (var stream = new System.IO.MemoryStream())
            {
                routerDb.Serialize(stream, true);

                Console.WriteLine(DateTime.Now);
                Console.WriteLine("Saving database to disk");
                using (var fileStream = new FileStream(@"C:\Maps\russia-latest.osm.pbf.router", FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                {
                    stream.Position = 0;
                    stream.CopyTo(fileStream);
                }
            }

            Console.WriteLine(DateTime.Now);
            Console.WriteLine("Finished");
        }
juliusfriedman commented 4 years ago

From what I recall the nuget packages were not able to work in 64 bit despite being built for anycpu.

You must build them manually for x64.

If your going to do that I suggest getting the latest https://github.com/itinero/reminiscence and to also see https://github.com/itinero/routing/pull/302