Skip to content

Commit dbe6106

Browse files
Added support for configuring the SDU used for sizing internal buffers.
1 parent 51cc3ba commit dbe6106

20 files changed

+205
-38
lines changed

doc/src/api_manual/connect_param.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ConnectParams Methods
5151
externalauth=None, mode=None, disable_oob=None, stmtcachesize=None, \
5252
edition=None, tag=None, matchanytag=None, config_dir=None, \
5353
appcontext=[], shardingkey=[], supershardingkey=[], debug_jdwp=None, \
54-
connection_id_prefix=None, ssl_context=None, handle=None)
54+
connection_id_prefix=None, ssl_context=None, sdu=None, handle=None)
5555

5656
Sets the default values for one or more of the parameters of an empty
5757
ConnectParams object. A default will be overriden when a connection string
@@ -248,6 +248,22 @@ ConnectParams Attributes
248248

249249
This attribute is supported in the python-oracledb Thin and Thick modes.
250250

251+
.. attribute:: ConnectParams.sdu
252+
253+
This read-only attribute is an integer that returns the requested size of
254+
the Session Data Unit (SDU), in bytes. The value tunes internal buffers
255+
used for communication to the database. Bigger values can increase
256+
throughput for large queries or bulk data loads, but at the cost of higher
257+
memory use. The SDU size that will actually be used is negotiated down to
258+
the lower of this value and the database network SDU configuration value.
259+
See the `SQL*Net documentation
260+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&
261+
id=GUID-86D61D6F-AD26-421A-BABA-77949C8A2B04>`__ for more details.
262+
263+
This attribute is supported in the python-oracledb Thin and Thick modes.
264+
265+
.. versionadded:: 2.0.0
266+
251267
.. attribute:: ConnectParams.server_type
252268

253269
This read-only attribute is a string that returns the type of server

doc/src/api_manual/module.rst

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Oracledb Methods
4848
edition=None, tag=None, matchanytag=False, \
4949
config_dir=oracledb.defaults.config_dir, appcontext=[], \
5050
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
51-
connection_id_prefix=None, ssl_context=None, handle=0)
51+
connection_id_prefix=None, ssl_context=None, sdu=8192, handle=0)
5252

5353
Constructor for creating a connection to the database. Returns a
5454
:ref:`Connection Object <connobj>`. All parameters are optional and can be
@@ -303,6 +303,17 @@ Oracledb Methods
303303
the default SSLContext object cannot be used. This value is only used in
304304
the python-oracledb Thin mode.
305305

306+
The ``sdu`` parameter is expected to be an integer that returns the
307+
requested size of the Session Data Unit (SDU), in bytes. The value tunes
308+
internal buffers used for communication to the database. Bigger values can
309+
increase throughput for large queries or bulk data loads, but at the cost
310+
of higher memory use. The SDU size that will actually be used is
311+
negotiated down to the lower of this value and the database network SDU
312+
configuration value. See the `SQL*Net documentation <https://www.oracle.
313+
com/pls/topic/lookup?ctx=dblatest&id=GUID-86D61D6F-AD26-421A-BABA-
314+
77949C8A2B04>`__ for more details. This value is used in both the
315+
python-oracledb Thin and Thick modes. The default value is 8192 bytes.
316+
306317
If the ``handle`` parameter is specified, it must be of type OCISvcCtx\*
307318
and is only of use when embedding Python in an application (like
308319
PowerBuilder) which has already made the connection. The connection thus
@@ -312,7 +323,7 @@ Oracledb Methods
312323

313324
.. versionchanged:: 2.0.0
314325

315-
The ``ssl_context`` parameter was added.
326+
The ``ssl_context`` and ``sdu`` parameters were added.
316327

317328
.. function:: ConnectParams(user=None, proxy_user=None, password=None, \
318329
newpassword=None, wallet_password=None, access_token=None, host=None, \
@@ -326,7 +337,7 @@ Oracledb Methods
326337
edition=None, tag=None, matchanytag=False, \
327338
config_dir=oracledb.defaults.config_dir, appcontext=[], \
328339
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
329-
connection_id_prefix=None, ssl_context=None, handle=0)
340+
connection_id_prefix=None, ssl_context=None, sdu=8192, handle=0)
330341

331342
Contains all the parameters that can be used to establish a connection to
332343
the database.
@@ -546,14 +557,25 @@ Oracledb Methods
546557
the default SSLContext object cannot be used. This value is only used in
547558
the python-oracledb Thin mode.
548559

560+
The ``sdu`` parameter is expected to be an integer that returns the
561+
requested size of the Session Data Unit (SDU), in bytes. The value tunes
562+
internal buffers used for communication to the database. Bigger values can
563+
increase throughput for large queries or bulk data loads, but at the cost
564+
of higher memory use. The SDU size that will actually be used is
565+
negotiated down to the lower of this value and the database network SDU
566+
configuration value. See the `SQL*Net documentation <https://www.oracle.
567+
com/pls/topic/lookup?ctx=dblatest&id=GUID-86D61D6F-AD26-421A-BABA-
568+
77949C8A2B04>`__ for more details. This value is used in both the
569+
python-oracledb Thin and Thick modes. The default value is 8192 bytes.
570+
549571
The ``handle`` parameter is expected to be an integer which represents a
550572
pointer to a valid service context handle. This value is only used in the
551573
python-oracledb Thick mode. It should be used with extreme caution. The
552574
default value is 0.
553575

554576
.. versionchanged:: 2.0.0
555577

556-
The ``ssl_context`` parameter was added.
578+
The ``ssl_context`` and ``sdu`` parameters were added.
557579

558580
.. function:: create_pool(dsn=None, pool_class=oracledb.ConnectionPool, \
559581
params=None, min=1, max=2, increment=1, \
@@ -573,7 +595,7 @@ Oracledb Methods
573595
edition=None, tag=None, matchanytag=False, \
574596
config_dir=oracledb.defaults.config_dir, appcontext=[], \
575597
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
576-
connection_id_prefix=None, ssl_context=None, handle=0)
598+
connection_id_prefix=None, ssl_context=None, sdu=8192, handle=0)
577599

578600
Creates a connection pool with the supplied parameters and returns the
579601
:ref:`ConnectionPool object <connpool>` for the pool. See :ref:`Connection
@@ -875,24 +897,35 @@ Oracledb Methods
875897
the default SSLContext object cannot be used. This value is only used in
876898
the python-oracledb Thin mode.
877899

900+
The ``sdu`` parameter is expected to be an integer that returns the
901+
requested size of the Session Data Unit (SDU), in bytes. The value tunes
902+
internal buffers used for communication to the database. Bigger values can
903+
increase throughput for large queries or bulk data loads, but at the cost
904+
of higher memory use. The SDU size that will actually be used is
905+
negotiated down to the lower of this value and the database network SDU
906+
configuration value. See the `SQL*Net documentation <https://www.oracle.
907+
com/pls/topic/lookup?ctx=dblatest&id=GUID-86D61D6F-AD26-421A-BABA-
908+
77949C8A2B04>`__ for more details. This value is used in both the
909+
python-oracledb Thin and Thick modes. The default value is 8192 bytes.
910+
878911
If the ``handle`` parameter is specified, it must be of type OCISvcCtx\*
879912
and is only of use when embedding Python in an application (like
880913
PowerBuilder) which has already made the connection. The connection thus
881914
created should *never* be used after the source handle has been closed or
882915
destroyed. This value is only used in the python-oracledb Thick mode. It
883916
should be used with extreme caution. The default value is 0.
884917

885-
.. versionchanged:: 2.0.0
886-
887-
The ``ssl_context`` parameter was added.
888-
889918
In the python-oracledb Thick mode, connection pooling is handled by
890919
Oracle's `Session pooling <https://www.oracle.com/pls/topic/lookup?
891920
ctx=dblatest&id=GUID-F9662FFB-EAEF-495C-96FC-49C6D1D9625C>`__ technology.
892921
This allows python-oracledb applications to support features like
893922
`Application Continuity <https://www.oracle.com/pls/topic/lookup?
894923
ctx=dblatest&id=GUID-A8DD9422-2F82-42A9-9555-134296416E8F>`__.
895924

925+
.. versionchanged:: 2.0.0
926+
927+
The ``ssl_context`` and ``sdu`` parameters were added.
928+
896929

897930
.. function:: Cursor(connection)
898931

@@ -1014,7 +1047,7 @@ Oracledb Methods
10141047
edition=None, tag=None, matchanytag=False, \
10151048
config_dir=oracledb.defaults.config_dir, appcontext=[], \
10161049
shardingkey=[], supershardingkey=[], debug_jdwp=None, \
1017-
connection_id_prefix=None, ssl_context=None, handle=0)
1050+
connection_id_prefix=None, ssl_context=None, sdu=8192, handle=0)
10181051

10191052
Creates and returns a :ref:`PoolParams Object <poolparam>`. The object
10201053
can be passed to :meth:`oracledb.create_pool()`.
@@ -1286,14 +1319,25 @@ Oracledb Methods
12861319
the default SSLContext object cannot be used. This value is only used in
12871320
the python-oracledb Thin mode.
12881321

1322+
The ``sdu`` parameter is expected to be an integer that returns the
1323+
requested size of the Session Data Unit (SDU), in bytes. The value tunes
1324+
internal buffers used for communication to the database. Bigger values can
1325+
increase throughput for large queries or bulk data loads, but at the cost
1326+
of higher memory use. The SDU size that will actually be used is
1327+
negotiated down to the lower of this value and the database network SDU
1328+
configuration value. See the `SQL*Net documentation <https://www.oracle.
1329+
com/pls/topic/lookup?ctx=dblatest&id=GUID-86D61D6F-AD26-421A-BABA-
1330+
77949C8A2B04>`__ for more details. This value is used in both the
1331+
python-oracledb Thin and Thick modes. The default value is 8192 bytes.
1332+
12891333
The ``handle`` parameter is expected to be an integer which represents a
12901334
pointer to a valid service context handle. This value is only used in the
12911335
python-oracledb Thick mode. It should be used with extreme caution. The
12921336
default value is 0.
12931337

12941338
.. versionchanged:: 2.0.0
12951339

1296-
The ``ssl_context`` parameter was added.
1340+
The ``ssl_context`` and ``sdu`` parameters were added.
12971341

12981342
.. function:: Time(hour, minute, second)
12991343

doc/src/api_manual/pool_params.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ PoolParams Methods
4646
externalauth=None, mode=None, disable_oob=None, stmtcachesize=None, \
4747
edition=None, tag=None, matchanytag=None, config_dir=None, \
4848
appcontext=[], shardingkey=[], supershardingkey=[], debug_jdwp=None, \
49-
connection_id_prefix=None, ssl_context=None, handle=None)
49+
connection_id_prefix=None, ssl_context=None, sdu=None, handle=None)
5050

5151
Sets one or more of the parameters.
5252

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Thin Mode Changes
1717
names with more than 255 UTF-8 encoded bytes.
1818
#) Added support for an Oracle Database 23c JSON feature improving JSON
1919
storage usage.
20+
#) Added parameter :attr:`ConnectParams.sdu` for configuring the Session Data
21+
Unit (SDU) size for sizing internal buffers used for tuning communication
22+
with the database.
2023
#) Fixed bug in detecting the current time zone
2124
(`issue 257 <https://github.com/oracle/python-oracledb/issues/257>`__).
2225
#) Added connection establishment parameter :data:`ConnectParams.ssl_context`

doc/src/user_guide/appendix_b.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ attributes.
164164
The ``ENABLE=BROKEN`` connect descriptor option is not supported in
165165
python-oracledb Thin mode. Use ``expire_time`` instead.
166166

167-
The ``Session Data Unit (SDU)`` connect descriptor option that is used to tune
168-
network transfers is not supported in python-oracledb Thin mode. The value is
169-
hard-coded as 8 KB. In python-oracledb Thick mode, the SDU connect descriptor
170-
option and equivalent ``sqlnet.ora`` setting are used.
171-
172167
If a name is given as a connect string, then the python-oracledb Thin mode will
173168
consider it as a Net Service Name and not as the minimal Easy Connect string of
174169
a hostname. The given connect string will be looked up in a ``tnsnames.ora``

doc/src/user_guide/tuning.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,20 @@ Some general tuning tips are:
4646

4747
* Tune your network. For example, when inserting or retrieving a large number
4848
of rows (or for large data), or when using a slow network, then tune the
49-
Oracle Network Session Data Unit (SDU) and socket buffer sizes, see `Oracle
50-
Net Services: Best Practices for Database Performance and High Availability
49+
Oracle Network Session Data Unit (SDU) and socket buffer sizes, see
50+
`Configuring Session Data Unit
51+
<https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-86D61D6F-AD26-421A-BABA-77949C8A2B04>`__
52+
and `Oracle Net Services: Best Practices for Database Performance and High
53+
Availability
5154
<https://static.rainfocus.com/oracle/oow19/sess/1553616880266001WLIh/PF/
5255
OOW19_Net_CON4641_1569022126580001esUl.pdf>`__.
5356

57+
In python-oracledb Thick mode the SDU size is configured in the
58+
:ref:`optnetfiles`. In python-oracledb Thin mode, the SDU size can be passed
59+
as a connection or pool creation parameter. In both modes it may optionally
60+
be set in the connection :ref:`Easy Connect string <easyconnect>` or
61+
:ref:`connect descriptor <netservice>`.
62+
5463
* Do not commit or rollback unnecessarily. Use :attr:`Connection.autocommit`
5564
on the last of a sequence of DML statements.
5665

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ cdef class Description(ConnectParamsNode):
134134
public uint32_t expire_time
135135
public uint32_t retry_count
136136
public uint32_t retry_delay
137+
public uint32_t sdu
137138
public double tcp_connect_timeout
138139
public str service_name
139140
public str server_type

src/oracledb/connect_params.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(
9393
debug_jdwp: str = None,
9494
connection_id_prefix: str = None,
9595
ssl_context: Any = None,
96+
sdu: int = 8192,
9697
handle: int = 0,
9798
threaded: bool = True,
9899
encoding: str = None,
@@ -250,6 +251,13 @@ def __init__(
250251
parameter should only be specified if the default SSLContext object
251252
cannot be used (default: None)
252253
254+
- sdu: the requested size of the Session Data Unit (SDU), in bytes. The
255+
value tunes internal buffers used for communication to the database.
256+
Bigger values can increase throughput for large queries or bulk data
257+
loads, but at the cost of higher memory use. The SDU size that will
258+
actually be used is negotiated down to the lower of this value and
259+
the database network SDU configuration value (default: 8192)
260+
253261
- handle: an integer representing a pointer to a valid service context
254262
handle. This value is only used in thick mode. It should be used with
255263
extreme caution (default: 0)
@@ -293,7 +301,8 @@ def __repr__(self):
293301
+ f"supershardingkey={self.supershardingkey!r}, "
294302
+ f"debug_jdwp={self.debug_jdwp!r}, "
295303
+ f"connection_id_prefix={self.connection_id_prefix!r}, "
296-
+ f"ssl_context={self.ssl_context!r}"
304+
+ f"ssl_context={self.ssl_context!r}, "
305+
+ f"sdu={self.sdu!r}"
297306
+ ")"
298307
)
299308

@@ -506,6 +515,19 @@ def retry_delay(self) -> Union[list, int]:
506515
"""
507516
return self._impl.retry_delay
508517

518+
@property
519+
@_description_attr
520+
def sdu(self) -> Union[list, int]:
521+
"""
522+
The requested size of the Session Data Unit (SDU), in bytes. The value
523+
tunes internal buffers used for communication to the database. Bigger
524+
values can increase throughput for large queries or bulk data loads,
525+
but at the cost of higher memory use. The SDU size that will actually
526+
be used is negotiated down to the lower of this value and the database
527+
network SDU configuration value.
528+
"""
529+
return self._impl.sdu
530+
509531
@property
510532
@_description_attr
511533
def server_type(self) -> Union[list, str]:
@@ -699,6 +721,7 @@ def set(
699721
debug_jdwp: str = None,
700722
connection_id_prefix: str = None,
701723
ssl_context: Any = None,
724+
sdu: int = None,
702725
handle: int = None,
703726
threaded: bool = None,
704727
encoding: str = None,
@@ -847,6 +870,13 @@ def set(
847870
parameter should only be specified if the default SSLContext object
848871
cannot be used
849872
873+
- sdu: the requested size of the Session Data Unit (SDU), in bytes. The
874+
value tunes internal buffers used for communication to the database.
875+
Bigger values can increase throughput for large queries or bulk data
876+
loads, but at the cost of higher memory use. The SDU size that will
877+
actually be used is negotiated down to the lower of this value and
878+
the database network SDU configuration value
879+
850880
- handle: an integer representing a pointer to a valid service context
851881
handle. This value is only used in thick mode. It should be used with
852882
extreme caution

src/oracledb/connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ def connect(
11781178
debug_jdwp: str = None,
11791179
connection_id_prefix: str = None,
11801180
ssl_context: Any = None,
1181+
sdu: int = 8192,
11811182
handle: int = 0,
11821183
threaded: bool = True,
11831184
encoding: str = None,
@@ -1356,6 +1357,13 @@ def connect(
13561357
should only be specified if the default SSLContext object cannot be used
13571358
(default: None)
13581359
1360+
- sdu: the requested size of the Session Data Unit (SDU), in bytes. The
1361+
value tunes internal buffers used for communication to the database.
1362+
Bigger values can increase throughput for large queries or bulk data
1363+
loads, but at the cost of higher memory use. The SDU size that will
1364+
actually be used is negotiated down to the lower of this value and the
1365+
database network SDU configuration value (default: 8192)
1366+
13591367
- handle: an integer representing a pointer to a valid service context
13601368
handle. This value is only used in thick mode. It should be used with
13611369
extreme caution (default: 0)

src/oracledb/impl/base/connect_params.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ _tnsnames_files = {}
6565
cdef str DEFAULT_PROTOCOL = "tcp"
6666
cdef uint32_t DEFAULT_PORT = 1521
6767
cdef double DEFAULT_TCP_CONNECT_TIMEOUT = 60
68+
cdef uint32_t DEFAULT_SDU = 8192
6869

6970

7071
cdef int _add_container(dict args, str name, object value) except -1:
@@ -790,6 +791,7 @@ cdef class Description(ConnectParamsNode):
790791
ConnectParamsNode.__init__(self, True)
791792
self.tcp_connect_timeout = DEFAULT_TCP_CONNECT_TIMEOUT
792793
self.ssl_server_dn_match = True
794+
self.sdu = DEFAULT_SDU
793795

794796
cdef str _build_duration_str(self, double value):
795797
"""
@@ -830,6 +832,8 @@ cdef class Description(ConnectParamsNode):
830832
if self.tcp_connect_timeout != DEFAULT_TCP_CONNECT_TIMEOUT:
831833
temp = self._build_duration_str(self.tcp_connect_timeout)
832834
parts.append(f"(TRANSPORT_CONNECT_TIMEOUT={temp})")
835+
if self.sdu != DEFAULT_SDU:
836+
parts.append(f"(SDU={self.sdu})")
833837

834838
# add address lists, but if the address list contains only a single
835839
# entry and that entry does not have a host, the other parts aren't
@@ -894,6 +898,7 @@ cdef class Description(ConnectParamsNode):
894898
description.source_route = self.source_route
895899
description.retry_count = self.retry_count
896900
description.retry_delay = self.retry_delay
901+
description.sdu = self.sdu
897902
description.tcp_connect_timeout = self.tcp_connect_timeout
898903
description.ssl_server_dn_match = self.ssl_server_dn_match
899904
description.ssl_server_cert_dn = self.ssl_server_cert_dn
@@ -925,6 +930,8 @@ cdef class Description(ConnectParamsNode):
925930
_set_bool_param(args, "source_route", &self.source_route)
926931
_set_uint_param(args, "retry_count", &self.retry_count)
927932
_set_uint_param(args, "retry_delay", &self.retry_delay)
933+
_set_uint_param(args, "sdu", &self.sdu)
934+
self.sdu = min(max(self.sdu, 512), 2097152) # sanitize SDU
928935
_set_duration_param(args, "tcp_connect_timeout",
929936
&self.tcp_connect_timeout)
930937

0 commit comments

Comments
 (0)