@@ -33,10 +33,10 @@ <h2>Contents</h2>
33
33
</ li >
34
34
< li > < a href ="#pooling "> 2. Connection Pooling</ a >
35
35
< ul >
36
- < li > 2.1 Session pooling</ li >
37
- < li > 2.2 Session pool experiments</ li >
36
+ < li > 2.1 Connection pooling</ li >
37
+ < li > 2.2 Connection pool experiments</ li >
38
38
< li > 2.3 Creating a DRCP Connection</ li >
39
- < li > 2.4 Session pooling and DRCP</ li >
39
+ < li > 2.4 Connection pooling and DRCP</ li >
40
40
< li > 2.5 More DRCP investigation</ li >
41
41
</ ul >
42
42
</ li >
@@ -112,7 +112,7 @@ <h2><a name="preface">Preface</a></h2>
112
112
113
113
< ol >
114
114
< li > < p > < a target ="_blank " href ="https://www.python.org/ "> Python</ a > . Version 3.6 (or later) is preferred.</ p > </ li >
115
- < li > < p > cx_Oracle version 7.2 (or later) and the Oracle Client libraries.</ p >
115
+ < li > < p > cx_Oracle version 7.3 (or later) and the Oracle Client libraries.</ p >
116
116
< ul >
117
117
< li > < a target ="_blank " href ="https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#installing-cx-oracle-on-linux "> Linux</ a > </ li >
118
118
< li > < a target ="_blank " href ="https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#installing-cx-oracle-on-macos "> macOS</ a > - please note the special instructions for macOS in the link.</ li >
@@ -131,6 +131,14 @@ <h2><a name="preface">Preface</a></h2>
131
131
sqlplus sys/yoursyspassword@localhost/orclpdb1 as sysdba @sql/SetupSamples
132
132
</ pre >
133
133
134
+ < p > If DRCP is not already running, connect to the SYS user again in
135
+ SQL*Plus and execute the command:</ p >
136
+
137
+ < pre >
138
+ execute dbms_connection_pool.start_pool()
139
+ </ pre >
140
+
141
+
134
142
< h2 > < a name ="connectioninformation "> Connection Information</ a > </ h2 >
135
143
136
144
< p > The database connection information is set in two files:
@@ -409,7 +417,7 @@ <h4>1.6 Checking versions</h4>
409
417
< li > < h3 > < a name ="pooling "> 2. Connection Pooling</ a > </ h3 >
410
418
411
419
< ul >
412
- < li > < h4 > 2.1 Session pooling</ h4 >
420
+ < li > < h4 > 2.1 Connection pooling</ h4 >
413
421
414
422
< p > Review the code contained in < code > connect_pool.py</ code > :</ p >
415
423
< pre >
@@ -441,22 +449,22 @@ <h4>1.6 Checking versions</h4>
441
449
</ pre >
442
450
443
451
< p > The < code > SessionPool()</ code > function creates a pool of
444
- Oracle "sessions" for the user. Sessions in the pool
445
- can be used by cx_Oracle connections by calling
446
- < code > pool.acquire() </ code > . The initial pool size is 2 sessions.
447
- The maximum size is 5 sessions . When the pool needs to grow, 1 new
448
- session will be created at a time. The pool can shrink back to the
449
- minimum size of 2 when sessions are no longer in use.</ p >
452
+ Oracle connections for the user. Connections in the pool can
453
+ be used by cx_Oracle by calling < code > pool.acquire() </ code > .
454
+ The initial pool size is 2 connections. The maximum size is 5
455
+ connections . When the pool needs to grow, 1 new connection
456
+ will be created at a time. The pool can shrink back to the
457
+ minimum size of 2 when connections are no longer in use.</ p >
450
458
451
459
< p > The < code > def Query():</ code > line creates a method that
452
460
is called by each thread. </ p >
453
461
454
462
< p > In the method, the < code > pool.acquire()</ code > call gets
455
- one session from the pool (as long as less than 5 are
456
- already in use). This session is used in a loop of 4
463
+ one connection from the pool (as long as less than 5 are
464
+ already in use). This connection is used in a loop of 4
457
465
iterations to query the sequence < code > myseq</ code > . At the
458
466
end of the method, cx_Oracle will automatically close the
459
- cursor and release the session back to the pool for
467
+ cursor and release the connection back to the pool for
460
468
reuse.</ p >
461
469
462
470
< p > The < code > seqval, = cur.fetchone()</ code > line fetches a
@@ -479,7 +487,7 @@ <h4>1.6 Checking versions</h4>
479
487
</ li >
480
488
481
489
< li >
482
- < h4 > 2.2 Session pool experiments</ h4 >
490
+ < h4 > 2.2 Connection pool experiments</ h4 >
483
491
484
492
485
493
< p > Review < code > connect_pool2.py</ code > , which has a loop for the number
@@ -521,19 +529,20 @@ <h4>2.2 Session pool experiments</h4>
521
529
522
530
< p > Experiment with different values of the pool parameters and
523
531
< code > numberOfThreads</ code > . Larger initial pool sizes will make the
524
- pool creation slower, but the sessions will be available immediately
525
- when needed. When < code > numberOfThreads</ code > exceeds the maximum
526
- size of the pool, the < code > acquire()</ code > call will generate an
527
- error. Adding the additional argument < code > getmode =
532
+ pool creation slower, but the connections will be available immediately
533
+ when needed. When < code > numberOfThreads</ code > exceeds the maximum size
534
+ of the pool, the < code > acquire()</ code > call will generate an error such
535
+ as "ORA-24459: OCISessionGet() timed out waiting for pool to create new
536
+ connections". Adding the additional argument < code > getmode =
528
537
cx_Oracle.SPOOL_ATTRVAL_WAIT</ code > to the
529
538
< code > cx_Oracle.SessionPool()</ code > call will prevent the exception
530
- from taking place, but will cause the thread to wait until a session
539
+ from taking place, but will cause the thread to wait until a connection
531
540
is available.</ p >
532
541
533
542
< p > Pool configurations where < code > min</ code > is the same as
534
543
< code > max</ code > (and < code > increment = 0</ code > ) are often
535
- recommended as a way to avoid connection storms on the database
536
- server.</ p >
544
+ recommended as a best practice. This avoids connection storms on the
545
+ database server.</ p >
537
546
538
547
</ li >
539
548
@@ -545,7 +554,7 @@ <h4>2.3 Creating a DRCP Connection</h4>
545
554
server processes.</ p >
546
555
547
556
< p > Below left is a diagram without DRCP. Every application
548
- connection or session has its own 'dedicated' database server
557
+ connection has its own 'dedicated' database server
549
558
process. Application connect and close calls require the expensive
550
559
create and destroy of those database server processes. To avoid these
551
560
costs, scripts may hold connections open even when not doing
@@ -572,7 +581,7 @@ <h4>2.3 Creating a DRCP Connection</h4>
572
581
required. However, if database host memory is large enough, then
573
582
the default, 'dedicated' server process model is generally
574
583
recommended. If DRCP is enabled, it is best used in conjunction
575
- with cx_Oracle session pooling.</ p >
584
+ with cx_Oracle's middle-tier connection pooling.</ p >
576
585
577
586
< p > Batch scripts doing long running jobs should generally use
578
587
dedicated connections. Both dedicated and DRCP servers can be used
@@ -617,9 +626,9 @@ <h4>2.3 Creating a DRCP Connection</h4>
617
626
</ li >
618
627
619
628
< li >
620
- < h4 > 2.4 Session pooling and DRCP</ h4 >
629
+ < h4 > 2.4 Connection pooling and DRCP</ h4 >
621
630
622
- < p > DRCP works well with session pooling.</ p >
631
+ < p > DRCP works well with cx_Oracle's connection pooling.</ p >
623
632
624
633
< p > Edit < code > connect_pool2.py</ code > , reset any changed pool options, and modify it to use DRCP:</ p >
625
634
< pre >
@@ -658,12 +667,13 @@ <h4>2.4 Session pooling and DRCP</h4>
658
667
659
668
< pre > < strong > python connect_pool2.py</ strong > </ pre >
660
669
661
- < p > If you get the error "ORA-24418: Cannot open further
670
+ < p > If you get an error "ORA-24459: OCISessionGet() timed out waiting for
671
+ pool to create new connections" or "ORA-24418: Cannot open further
662
672
sessions", it is because connection requests are being made
663
673
while the pool is starting or growing. Add the argument
664
674
< code > getmode = cx_Oracle.SPOOL_ATTRVAL_WAIT</ code > to the
665
675
< code > cx_Oracle.SessionPool()</ code > call so connection
666
- requests wait for pooled sessions to be available.</ p >
676
+ requests wait for pooled connections to be available.</ p >
667
677
668
678
< p > Open a new a terminal window and invoke SQL*Plus:</ p >
669
679
@@ -681,7 +691,7 @@ <h4>2.4 Session pooling and DRCP</h4>
681
691
< li >
682
692
< h4 > 2.5 More DRCP investigation</ h4 >
683
693
684
- < p > To explore the behaviors of session and DRCP pooling futher,
694
+ < p > To explore the behaviors of cx_Oracle connection pooling and DRCP pooling futher,
685
695
you could try changing the purity to
686
696
< code > cx_Oracle.ATTR_PURITY_NEW</ code > to see the effect on the
687
697
DRCP NUM_MISSES statistic.</ p >
@@ -921,7 +931,7 @@ <h4>2.5 More DRCP investigation</h4>
921
931
922
932
< pre > < strong > python query_arraysize.py</ strong > </ pre >
923
933
924
- < p > Reload a few times to see the average times.</ p >
934
+ < p > Rerun a few times to see the average times.</ p >
925
935
926
936
< p > Experiment with different arraysize values. For example, edit
927
937
< code > query_arraysize.py</ code > and change the arraysize to:</ p >
@@ -1042,7 +1052,7 @@ <h4>2.5 More DRCP investigation</h4>
1042
1052
< p > The '< code > rows</ code > ' array contains the data to be inserted.</ p >
1043
1053
1044
1054
< p > The < code > executemany()</ code > call inserts all rows. This
1045
- calls allows "array binding", which is an efficient way to
1055
+ call uses "array binding", which is an efficient way to
1046
1056
insert multiple records.</ p >
1047
1057
1048
1058
< p > The final part of the script queries the results back and displays them as a list of tuples.</ p >
@@ -1121,11 +1131,11 @@ <h4>2.5 More DRCP investigation</h4>
1121
1131
1122
1132
< p > The other data gets inserted and is queried back.</ p >
1123
1133
1124
- < p > At the end of the script, cx_Oracle will rollback an uncommitted transaction. If you want to commit results, you can use:</ p >
1134
+ < p > At the end of the script, cx_Oracle will roll back an uncommitted transaction. If you want to commit results, you can use:</ p >
1125
1135
1126
1136
< pre > con.commit()</ pre >
1127
1137
1128
- < p > To force a rollback in cx_Oracle , use:</ p >
1138
+ < p > To force cx_Oracle to roll back , use:</ p >
1129
1139
1130
1140
< pre > con.rollback()</ pre >
1131
1141
@@ -2202,7 +2212,7 @@ <h2><a name="summary">Summary</a></h2>
2202
2212
< p > In this tutorial, you have learned how to: </ p >
2203
2213
< ul >
2204
2214
< li > Create connections</ li >
2205
- < li > Use sessions pooling and Database Resident Connection Pooling</ li >
2215
+ < li > Use cx_Oracle connection pooling and Database Resident Connection Pooling</ li >
2206
2216
< li > Execute queries and fetch data</ li >
2207
2217
< li > Use bind variables</ li >
2208
2218
< li > Use PL/SQL stored functions and procedures</ li >
0 commit comments