godror

Contents

Go DRiver for ORacle User Guide

Godror Tuning

Correctness and simplicity is more important than speed, but the underlying ODPI-C library helps a lot with the lower levels, so the performance is not bad.

Some general recommendations:

Round-trips between Godror and Oracle Database

A round-trip is defined as the trip from the Oracle Client libraries (used by godror) to the database and back. Calling each godror function, or accessing each attribute, will require zero or more round-trips. Along with tuning an application’s architecture and tuning its SQL statements, a general performance and scalability goal is to minimize round-trips.

Oracle’s Automatic Workload Repository (AWR) reports show ‘SQL*Net roundtrips to/from client’ and are useful for finding the overall behavior of a system. Sometimes you may wish to find the number of round-trips used for a specific application. Snapshots of the V$SESSTAT view taken before and after doing some work can be used for this:

SELECT ss.value, sn.display_name
FROM v$sesstat ss, v$statname sn
WHERE ss.sid = SYS_CONTEXT('USERENV','SID')
AND ss.statistic# = sn.statistic#
AND sn.name LIKE '%roundtrip%client%'

Note running this query will also affect the round-trip count. You may want to execute it in a second connection but replace the SYS_CONTEXT() call with the value of first connection’s SID.

Query Performance

When queries (SELECT or WITH statements) are executed, the performance of fetching the rows from the database can be tuned with PrefetchCount() and FetchArraySize(). The best values can be found by experimenting with your application under the expected load of normal application use. This is because the cost of the extra memory copy from the prefetch buffers when fetching a large quantity of rows or very “wide” rows may outweigh the cost of a round-trip for a single godror user on a fast network. However under production application load, the reduction of round-trips may help performance and overall system scalability.

Here are some suggestions for the starting point to begin your tuning:

DML Performance

Instead of looping over DML statements (e.g. INSERT, UPDATE and DELETE), performance can be greatly improved by providing all the data at once using slices.

For example, instead of:

db.Exec("INSERT INTO table (a, b) VALUES (:1, :2)", 1, "a")
db.Exec("INSERT INTO table (a, b) VALUES (:1, :2)", 2, "b")

do:

db.Exec("INSERT INTO table (a, b) VALUES (:1, :2)", []int{1, 2}, []string{"a", "b"})