Database Reference
In-Depth Information
9) {
10) progressBarTest.Value++;
11) }
12)
}
In this example, OnPassCompleted is a custom event received by the main form, which then calls the
Invoke method to refresh a progress bar. The call to Invoke forces the execution of the progress bar
refresh on the UI thread, which is different than the thread on which the OnPassCompleted event was
raised.
Parallel Processing
In addition to asynchronous user interfaces, your code may need to execute on multiple processors. Two
primary scenarios can lead you to choose parallel processing for your application:
Many calculations . Your application is CPU intensive, especially if computations
can be independent from each other. Advanced graphics or complex
mathematical computations are examples of CPU-intensive operations.
Many waits . Your application needs to wait between each call, and the cost of
creating parallel threads and aggregating results is insignificant. Database shards
are an example: calling five databases in parallel is roughly five times faster than
calling five databases serially.
Two choices are available to write parallel processes. If you can, you should use the Task Parallel
Library (TPL), because it's easier:
Task Parallel Library . The TPL is a newer library that Microsoft is providing as
part of .NET 4.0. It allows you to take advantage of multiple CPUs quickly and
easily. You can find the TPL under System.Threading.Tasks .
Threads . Managing threads the old-fashioned way using the System.Threading
namespace gives you the most flexibility.
Shards
Shards offer another mechanism by which your code can read and write data against any number of
databases almost transparently. Later in this chapter, you create a horizontal partition shard (HPS) using
the read-write shard (RWS) design pattern as described in Chapter 2, with the round-robin access
method. A horizontal partition implies that all the databases have identical schema and that a given
record can written in any database that belongs to the shard. From a performance standpoint, reading
from multiple databases in parallel to search for records yields greater performance; however, your code
must keep breadcrumbs if you need to perform updates back to the correct database. Finally, using a
shard requires parallel processing for optimum performance.
Coding Strategies Summary
Table 2-1 provides a summary of the concepts discussed so far regarding some of the coding strategies
available to you when you develop against a SQL Azure database with performance in mind.
Search WWH ::




Custom Search