Beispiel #1
0
        public static void Run(string layers)
        {
            Console.WriteLine("Benchmarking " + layers);
            UrlGenerator urlGenerator = new UrlGenerator(layers);
            string       result       = "Layers: " + layers + "\r\n";
            string       result2      = "";

            for (int z = zMin; z <= zMax; z++)
            {
                List <TileRequest> requests = new List <TileRequest>();
                for (int i = 0; i < total; i++)
                {
                    TileRequest request = new TileRequest(urlGenerator.Get(z));
                    request.Send();
                    requests.Add(request);
                }
                requests.Sort();

                // calc statistics
                long sum = 0;
                for (int i = 0; i < effective; i++)
                {
                    sum += requests[i].milliSeconds;
                }
                result  += "zoom " + z + ": avg/" + (sum / effective) + " high/" + requests[0].milliSeconds + " low/" + requests[effective - 1].milliSeconds + "\r\n";
                result2 += requests[0].url + "\r\n";
            }

            File.AppendAllText(reportPath, result + result2 + "\r\n");
        }
Beispiel #2
0
        public void Start(int maxZoom)
        {
            Console.WriteLine("Estimated file count: " + (int)((xmax - xmin) * (ymax - ymin) * 1.333 / (1 << (2 * (zoom - maxZoom)))));
            int count = 0;

            for (int z = 0; z <= maxZoom; z++)
            {
                int shift = zoom - z;
                int x1    = Math.Max((xmin >> shift) - 4, 0);
                int x2    = Math.Min((xmax >> shift) + 4, (1 << z) - 1);
                int y1    = Math.Max((ymin >> shift) - 4, 0);
                int y2    = Math.Min((ymax >> shift) + 4, (1 << z) - 1);
                for (int x = x1; x <= x2; x++)
                {
                    for (int y = y1; y <= y2; y++)
                    {
                        if (count % 1000 == 0)
                        {
                            Console.Write(count + " ");
                        }
                        count++;
                        string      url     = urlTemplate.Replace("{z}", z.ToString()).Replace("{x}", x.ToString()).Replace("{y}", y.ToString());
                        TileRequest request = new TileRequest(url);
                        request.Send();
                        if (!request.success)
                        {
                            Console.WriteLine("Failed to access " + url);
                        }
                        else
                        {
                            Directory.CreateDirectory(XYZToFolder(x, y, z));
                            FileStream fileStream = new FileStream(XYZToPath(x, y, z), FileMode.Create);
                            request.imageStream.WriteTo(fileStream);
                            fileStream.Close();
                        }
                    }
                }
            }
            Console.WriteLine("\r\n" + count + " files are generated");
        }
Beispiel #3
0
        static void PrefillCache(string prefillUrl, string styleSet, string[] layers)
        {
            int sum = 0;

            for (int z = 0; z <= prefillMaxZoom; z++)
            {
                sum += (1 << z) * (1 << z);
            }
            Console.WriteLine("Start prefilling cache...");
            Console.WriteLine("Tile total count: " + sum);

            foreach (string layer in layers)
            {
                Console.WriteLine("Start requesting " + layer);
                Stopwatch watch = new Stopwatch();
                watch.Start();
                long slowest = 0;
                int  count   = 0;
                for (int z = 0; z <= prefillMaxZoom; z++)
                {
                    int xmax = 1 << z;
                    for (int x = 0; x < xmax; x++)
                    {
                        for (int y = 0; y < xmax; y++)
                        {
                            TileRequest ut = new TileRequest(prefillUrl + styleSet + "&x=" + x + "&y=" + y + "&z=" + z + "&layers=" + layer);
                            ut.Send();
                            slowest = Math.Max(slowest, ut.milliSeconds);
                            count++;
                            if (count % 100 == 0)
                            {
                                Console.Write(count + " ");
                            }
                        }
                    }
                }
                watch.Stop();
                Console.WriteLine("\r\nFinish in " + watch.Elapsed + ", avg/" + (watch.ElapsedMilliseconds / count) + ", high/" + slowest + "\r\n");
            }
        }