User Tools

Site Tools


map_suite_geocoder_performance_guide

This is an old revision of the document!


Map Suite Geocoder Performance Guide

Welcome to Map Suite Geocoder performance test and promotion guide, we strongly recommend you read the presentation of Map Suite Geocoder to know what is it and how is it work before reading this guide. If you have already understood Map Suite Geocoder, let's go on with this guide.

The purpose of this guide is to help you to know following things:

  • A simple introduction for inner structure and workflow of Map Suite Geocoder.
  • What is the bottleneck of Map Suite Geocoder performance.
  • How to improve the performance of batch query.

Structure and Workflow

This section will introduce the structure and workflow of Map Suite Geocoder roughly.

Data Source

The Geocoder uses a native data source with an optimized set of United States street based on the TIGER® data from the U.S. Census Bureau. Below Figure 1 shows a partial source data files.


Figure 1. Data source files.

The latest data from 2018 is available with purchase, you can refer our Blog to know the detail.

Open and Close Geocoder

After instantiating a UsaGeocoder in your code, you have to call Open function before doing any match queries, and it's recommended to call Close function after finishing your query. The code looks like:

UsaGeocoder usaGeocoder = new UsaGeocoder(sourceDataPath, MatchMode.Default, StreetNumberMatchingMode.Default);
usaGeocoder.Open();
// custom code for match queries
usaGeocoder.Close();

When opening a Geocoder, some source data you specified would be preprocessed and loaded into memory, most of them are index data that would be read frequently in match query. These data would be released from memory after close Geocoder.

You may see the MatchMode and StreetNumberMatchingMode when initializing the UsaGeocoder, they can be used to specify different match policies. It's important that the more strict policy the less match query time and vice versa. All code snippets in this guide use Default MatchMode with ExactMatch and Default StreetNumberMatchingMode with ExactMatch.

Match Query

The Geocoder supports three overloaded Match functions to do the match query, see below code snippet:

usaGeocoder.Match(sourceText: "12448 Angelo Dr. Frisco TX 75035-6470");
usaGeocoder.Match(streetAddress: "12448 Angelo Dr. Frisco TX", zip: "75035-6470");
usaGeocoder.Match(streetAddress: "12448 Angelo Dr.", city: "Frisco", state: "TX");
  • The 1st call with only one sourceText parameter would spend relative most time, because Geocoder would consider both geocoding and reverse geocoding when parsing the sourceText, it's not recommended to use this call when you only want to do geocoding.
  • The 2nd call with streetAddress and zip parameters is relative fastest, only geocoding would be considered and the match results would be returned directly.
  • The 3rd call with streetAddress, city and state parameters is slower than 2nd call, the different is that the results would be handled to filter city and state before returning.

To test the ultimate performance of Geocoder, we use the 2nd call in this guide.

Bottleneck of Performance

In this section we will discuss what is the bottleneck of Map Suite Geocoder performance.

IO

The most time spent of Geocoder is on IO. Due to the size of source data is about 9.06 GB, Geocoder cannot load all of them into memory when opening, if we do that, it will spend a lot of time to open Geocoder. We already had optimized and made the Geocoder to load necessary source data when opening, and added in memory cache to increase the read speed, it still would read data from files when doing match query, the IO is the one of a bottleneck of performance.

Normalize Text

The another bottleneck is input/output text normalization, customer wants to input various of text to do the match query, Geocoder have to split and explain them at first, then compare the normalized text cluster with cache or file data to do the match. The matched results also need to be normalized as the Geocoder result. We always keep to update our normalization algorithm to make it more faster and accurate.

Performance Test

Below Figure 2 is the test result that did 1,000 queries, the execution time is 4.669 seconds:


Figure 2. Performance test with 1,000 queries.

And the below Figure 3 is the test result that did 10,000 queries, the execution time is 16.588 seconds:


Figure 3. Performance test with 10,000 queries.

It's obvious that the most time spent is on IO (includes file or cache read), then normalization.

Performance Improvement

In this section we will help you to improve the geocoding when doing huge queries.

Using Multi-thread

With the limitation of cache and file read, Geocoder doesn't support inner multi-thread to do the batch query. But it's bad if customer wants to do a huge query with more than 100,000 input text, below code snippet will help you to improve the query performance:

// convert original custom data to address-zip map list
string[] records = File.ReadAllLines(args[1]);
var addressZips = new List<List<string>>();
foreach (var item in records)
{
    var values = item.Split(',');
    string addressName = values[5];
    string zip = values[8];
    addressZips.Add(new List<string>() { addressName, zip });
}
 
// split address-zip map list to task chunks
int taskCount = 8;
int recordCount = addressZips.Count;
var taskAddressZips = new List<List<List<string>>>();
for (int i = 0; i < taskCount; i++)
{
    taskAddressZips.Add(new List<List<string>>());
}
 
int itemCount = 0;
int taskItemCount = 0;
while (itemCount < recordCount)
{
    if (taskAddressZips[taskItemCount].Count <= recordCount / taskCount + 1)
    {
        taskAddressZips[taskItemCount].Add(addressZips[itemCount]);
    }
    else
    {
        taskItemCount += 1;
        taskAddressZips[taskItemCount].Add(addressZips[itemCount]);
    }
 
    itemCount += 1;
}
 
// generate tasks to geocoding
var tasks = new List<Task>();
for (int i = 0; i < taskCount; i++)
{
    var task = new Task((innerOjb) =>
    {
        UsaGeocoder usaGeocoder = new UsaGeocoder(args[0]);
        usaGeocoder.Open();
 
        var innerAddressZips = innerOjb as List<List<string>>;
        for (int j = 0; j < innerAddressZips.Count; j++)
        {
            var results = usaGeocoder.Match(innerAddressZips[j][0], innerAddressZips[j][1]);
        }
 
        usaGeocoder.Close();
 
    }, taskAddressZips[i]);
 
    tasks.Add(task);
}
 
// run all tasks
foreach (var task in tasks)
{
    task.Start();
}
Task.WaitAll(tasks.ToArray());

We preprocess the input texts to split them to 8 chunks, then generate 8 tasks to do the batch queries, each task maintains independent Geocoder to avoid multi-thread error. Below Figure 4 shows the elapsed time compare:


Figure 4. Query compare.

It shows that we improved about three times speed after using multi-thread.

Hardware Performance

We used the following machine hardware device to do the test in Figure 4.

  • CPU: Intel® Core™ i7-4790 CPU @ 3.60GHz
  • Memory: 8.00 GB
  • Disk: Crucial CT500MX200SSD1
  • System: Windows 10 64-bit

And the hardware usage when querying is:

  • CPU: 70% - 90%
  • Memory: 300 MB +
  • IO: 30 MB/Seconds

We also used different Amazon® instances to do the same test to dig the limitation of the Geocoder with multi-thread. Below Figure 5 is the test results:


Figure 5. Performance test result on Amazon® instance.

Note that we set the thread count to 8 because we always tend to make the thread count to match the CPU core count, if you start too much threads, the query speed would decrease instead.

map_suite_geocoder_performance_guide.1553075751.txt.gz · Last modified: 2019/03/20 09:55 by tgwikiupdate