In this post, originally written by Glenn Paulley and posted to sybase.com in October of 2009, Glenn talks more about the differences between the JConnect and SQL Anywhere JDBC drivers.
In a previous post I briefly described some of the differences between the jConnect JDBC driver and the iAnywhere JDBC driver when used with SQL Anywhere. A whitepaper on sybase.com summarizes the architectural differences between the two drivers.
Both the jConnect and iAnywhere drivers support JDBC 3.0. jConnect is a "pure Java" solution (termed a Type 4 JDBC driver), while the iAnywhere driver is a Type 1 driver because of its reliance on the SQL Anywhere ODBC driver which must be properly installed. It is sometimes argued that a "pure Java" solution is better/faster/more robust; hence, on paper, jConnect should be "better" than the iAnywhere Type 1 driver. However, if one looks more closely, the significant differences between the two solutions are (1) memory management, (2) the use of the TDS wire protocol, and (3) differences in semantics. We look at each of these in turn.
With a pure Java solution:
Unfortunately, the weakness of pure Java solutions is the same: memory management. The application programmer has little or no real control over the lifespan of an object. Moreover, the programmer has no effective control over garbage collection; garbage collection can kick in at critical times, resulting in random and unreproducible performance problems.
With a hybrid solution such as the iAnywhere JDBC driver, the most important advantage is memory management:
However, as with pure Java, the greatest disadvantage of a hybrid solution is - you guessed it - also memory management. In the hybrid case, non-Java objects need to be managed explicitly; program errors lead to memory leaks at best, and memory corruption or GPFs at worst. Moreover, if Java object references are held too long, Java garbage collection won't kick in.
jConnect uses Sybase ASE's native wire protocol, the Tabular Data Stream (TDS) protocol, whereas the iAnywhere JDBC driver uses SQL Anywhere's native wire protocol which is called Command Sequence (CMDSEQ). There are both semantic and performance differences between the use of the two protocols; each has advantages and disadvantages.
An advantage of TDS is that it supports "fire hose" cursors. That is, with a single TDS language command token one can instruct the server to execute a set of statements, describe all the result sets, and return all the results in one go to the client. In situations where the application desires all of the rows of a result set(s), a fire hose cursor does offer a performance advantage by reducing the amount of round-trip traffic over the wire. However, this comes at a cost: it is the client that is responsible for caching the result set, and the client that must implement cursor scrolling. The TDS client supports a "window" of rows in the result set that the Java application can scroll through - both forwards and backwards. However, should scrolling occur to a range of rows outside this window the entire request is re-issued to the server - necessary since prior rows outside the "window" have been lost. Hence, in this model with scrollable cursors, cursor sensitivity semantics are impossible to guarantee. Moreover, with very large result sets the communication stream can become blocked if the client cannot process the returned rows quickly enough, which can, in turn, block the server.
While fire-hose cursors give an advantage to jConnect connections under the right circumstances, recently-added support for adaptive prefetching in CMDSEQ (see below) mitigates this advantage. Moreover, there are several additional features supported by the iAnywhere JDBC driver that provide advantages over jConnect. These include:
INSERT
statement. In contrast, the iAnywhere JDBC driver efficiently supports both wide inserts and wide fetches.SQL Anywhere version 11 introduced adaptive prefetch as a variant of prefetch behaviour with CMDSEQ connections. Prefetch is designed to reduce communication in a client-server environment by transferring sets of rows to the client in advance of a FETCH
request, and is enabled by default. Prefetching can be disabled outright by specifying the DisableMultiRowFetch connection parameter, or by setting the Prefetch connection option to OFF. Prefetch is turned off for cursors declared with sensitive value semantics.
With adaptive prefetching, a SQL Anywhere CMDSEQ client will automatically adjust the number of rows that are prefetched - increasing or decreasing - depending on application behaviour. A hard limit on the maximum number of rows that will be prefetched is 1000. Adaptive prefetching is also controlled by number of rows the application can FETCH
in one elapsed second. Adaptive prefetching is enabled for cursors for which all of the following are true:
FORWARD ONLY
, READ ONLY
(default) cursor types; ESQL: DYNAMIC SCROLL
(default), NO SCROLL
and INSENSITIVE
cursor types; all ADO.Net cursorsFETCH NEXT
operations are done (no absolute, relative or backwards fetching)GET DATA
to get column data in chunks (but using one GET DATA
to retrieve the value is fine).In addition to the automatic setting of connection options to ASE-equivalent settings upon connecting with jConnect - described in my previous post- there are other semantic differences with jConnect. They include:
CHAR
and BINARY
values are automatically padded upon retrieval from blank-padded databases.If a JDBC application wanted to use jConnect but not want Sybase ASE-like behaviour, then the application would have to:
RETURN_DATE_TIME_AS_STRING
to ON in order to get SQL Anywhere to always return DATE
/TIME
/TIMESTAMP
values as strings. This is to overcome the inability of TDS to handle dates prior to January 1, 1753.In a subsequent post I'll outline performance differences between the jConnect and iAnywhere drivers. In our experience with customer applications, most applications benefit from a significant performance boost by switching to the iAnywhere JDBC driver, occasionally up to a factor of two, depending on the nature of the application and the precise sequence of JDBC API calls issued by the application.
My thanks to colleague Karim Khamis for providing me with the background for this article.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
24 | |
11 | |
11 | |
8 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 |