Performance Issues
An asynchronous call typically executes more code than a corresponding synchronous call. However, the advantage of asynchronous calls derives from the fact that in any computation the majority of time is spent in I/O rather than actual computation. In a synchronous call, the thread waits for the I/O to complete; in the asynchronous call, the thread is free to do its next job.
An asynchronous call in the DB Interface Module can improve the performance of an application if and only if the application can make better use of the thread while the asynchronous call is in progress. Otherwise, a synchronous call may prove to be faster. The following example illustrates the problem.
 
int
main() {
RWDBDatabase aDb = RWDBManager::database(
"SYBASE_CT",
"sybase_server",
"sybase_user",
"password",
"DEMO_DB"
);
 
RWDBConnection asyncConn =
aDb.connection(RWDBConnection::Asynchronous); //1
RWDBResult result =
aSyncConn.executeSql(“create table X(y int)”); //2
 
assert(result.isValid()); //3
return 0;
}
This example is similar to the previous asynchronous example, except that the code does no useful work after the asynchronous call in //2. Note that in //3, it accesses the isValid() method of the returned object, which blocks the thread and completes the asynchronous call. No useful work is done between the asynchronous call in //2 and completion of the call in //3.