training on - oracle cloud · the core of java connection pool functionality, highly concurrent...
TRANSCRIPT
![Page 1: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/1.jpg)
![Page 2: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/2.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 2
Classroom TrainingLearning
SubscriptionLive Virtual Class
Training On Demand
Keep Learning with Oracle University
education.oracle.com
CloudTechnologyApplicationsIndustries
![Page 3: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/3.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Session Surveys
Help us help you!!• Oracle would like to invite you to take a moment to give
us your session feedback. Your feedback will help us to improve your conference.
• Please be sure to add your feedback for your attended sessions by using the Mobile Survey or in Schedule Builder.
3
![Page 4: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/4.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Java Connection Pool Performance and Scalability with Wait-Free
Programming
Yuri DolgovPrincipal Member of Technical StaffOracle CorporationJava Database Connectivity development groupOctober 25, 2015
![Page 5: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/5.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
5
![Page 6: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/6.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 6
Program Agenda
Problem
Requirements
How it works
Benchmark
Conclusion
1
2
3
4
5
![Page 7: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/7.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 7
Problem
Requirements
How it works
Benchmark
Conclusion
1
2
3
4
5
![Page 8: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/8.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 8
Non-wait-free connection pool’s performance
concurrent sessions (THREADS) 10 50 100 500 1000 5000 10000
old style CP (borrows/sec) 178890 201743 173464 134211 89263 41362 15404
0
50000
100000
150000
200000
250000
10 50 100 500 1000 5000 10000
borr
ows/
sec
concurrent sessions (THREADS)
old style CP (borrows/sec)
![Page 9: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/9.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 9
The problem
We need a concurrent data structure that does not degrade a performance in case of a large number of accessing threads.
A wait-free solution is desirable (lock-free if there is guaranteed system-wide progress, and wait-free if there is also guaranteed per-thread progress).
![Page 10: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/10.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 101010
Problem
Requirements
How it works
Benchmark
Conclusion
2
5
3
4
1
![Page 11: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/11.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 11
What is needed
A concurrent data structure for:
1. Fast element insertion
2. Fast element removal
3. Fast sequential search
4. Fast navigation
![Page 12: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/12.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 12
Generic example – all 6 are cuncurrently running threads
• Thread 1 puts an object ‘Potato’
• Thread 2 puts an object ‘Tomato’
• Thread 3 puts an object ‘Cucumber’
• Thread 4 looks for an object ‘Potato’ with specific color, size, specific shape, etc.
• Thread 5 navigates all vegetables and makes a list of them
• Thread 6 removes all objects ‘Tomato’ with specific size
![Page 13: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/13.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted13
Issue!
There is a locking issue here!
![Page 14: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/14.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Connection attributes
14
Attribute Description
Available Whether it is available or not
Valid Whether valid or not
URL Database
Username Database account username
Password Database account password
Origin, 1st dimension Origin 1 name
Origin, 2nd dimension Origin 2 name
Origin, 3rd dimension Origin 3 name
Origin, 4th dimension Origin 4 name
Labels List of connection’s labels, for cost-based search
![Page 15: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/15.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 15
Connection attributes (continued)
Attribute Description
Creation timestamp When a connection was created
Last borrow timestamp When a connection was borrowed for the last time
Last activity timestamp When there was a latest operation on a connection
Borrow count Cumulative borrow count
Borrow time Cumulative borrow time
Lots of other attributes
![Page 16: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/16.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 16
ActorsActor Description Typical
amount
User session threads
Usually a user thread that borrows a connection 0-unlimited
Inactive timer Closes inactive connections 1
Abandoned timer Makes abandoned connection available again 1
TTL timer Makes TTL-ed connections available again 1
Load balancer thread
Listens to the LB advisory and re-arranges connections among origins
1
Failover thread Listens to the FF events and re-arranges connections among instances
1
Worker threads Lots of various activities in the background: keeping the pool’s min/max bounds, validation, rebalancing, failover handling, etc.
N
![Page 17: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/17.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 17
Operations
Operation Actor Description
Borrow User Session Thread
Borrow any available valid connection
Borrow cheapest labeled
User Session Thread
Borrow a “cheapest” available valid connection for a given set of labels
Borrow on a proper instance
User Session Thread
Borrow an available valid connection while a) taking care of the proper load balancing; b) affinity-based borrow
Borrow cheapest labeled on a properinstance
User Session Thread
Combination of previous two types of borrow, appropriate instance depends on either load balancing or some type of affinity
![Page 18: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/18.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 18
Operations (continued)Operation Actor Description
Adjust pool size Worker Threads Add new available valid connections if total < minPoolSize, or get rid of some connections if total > maxPoolSize
Rearrange among accounts or origins
Worker Threads Close connections to some database accounts, create connections to some other database accounts
Rebalance Load Balancer Thread
Close some portion of connections on some instances and create some portion on another ones to match the load balancing advisory
Failover DOWN Event Processing
Failover Driver Thread
Drain all connections on an instance/host/database that is about to go DOWN, create some connections on other instances/databases/hosts to be within min-max bounds
![Page 19: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/19.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 19
Operations (continued)
Operation Actor Description
Failover UP Event Processing
Failover Driver Thread
Create connection on an instance/host/database that went UP and close connections on other instances/hosts/databases to match min-max bounds
Free Abandoned Connections
Abandoned Connections Timer
Navigate through a pool and free (make available) all abandoned connection
Free TTL-ed Connections
TTLed Connections Timer
Navigate through a pool and free (make available) all TTL-ed connections
Close Inactive Connections
Inactive Connections Timer
Navigate through a pool and close inactive connections
![Page 20: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/20.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 20
Possibility of Indexing:
• Some attributes can be indexed
• But hard to index everything (too many keys, partial match, etc.)
• KD-Tree (aka “Multidimensional tree”) – way to go, especially for huge pools; and we plan to implement it!
• We come up to a sequential search, which is not bad once in most cases a proper item is at the beginning of a sequence
![Page 21: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/21.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 21
final List<Item> pool = new ArrayList<Item>();
PROS:• Easy, available and well-known implementation
working in tons of applications• Earlier UCP implementation worked using
ArrayList
CONS:• Every insert, remove and search operation needs
to be synchronized
RESULT: not effective for the connection pool.
![Page 22: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/22.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 22
final List<Item> pool = new CopyOnWriteArrayList<Item>();
PROS:• Very effective non-blocking reads• Separate writes (into a copy, then a copy
becomes original by just flipping a reference)
CONS:• Good only for applications that do a lot of reads
but rarely write.
RESULT: not effective for the connection pool.
![Page 23: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/23.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 23
What is ‘synchronized’?Synchronization sample:
void onlyMe(Foo f) {synchronized(f) {
doSomething();}
}
is compiled into the following Java bytecode:Method void onlyMe(Foo)0 aload_1 // Push f1 dup // Duplicate it on the stack2 astore_2 // Store duplicate in local variable 23 monitorenter // Enter the monitor associated with f4 aload_0 // Holding the monitor, pass this and...5 invokevirtual #5 // ...call Example.doSomething()V8 aload_2 // Push local variable 2 (f)9 monitorexit // Exit the monitor associated with f10 goto 18 // Complete the method normally13 astore_3 // In case of any throw, end up here14 aload_2 // Push local variable 2 (f)15 monitorexit // Be sure to exit the monitor!16 aload_3 // Push thrown exception...17 athrow // ...then rethrow the value to the invoker18 return // Return in the normal case
Exception table:From To Target Type4 10 13 any13 16 13 any
![Page 24: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/24.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 24
monitorEntermonitorenter (from the JVM spec):
“Each object has a monitor associated with it. The thread that executes monitorenter gains ownership of the monitor associated with objectref. If another thread already owns the monitor
associated with objectref, the current thread
waits until the object is unlocked,
then tries again to gain ownership. If the current thread already owns the monitor associated with objectref, it increments a counter in the monitor indicating the number of times this thread has entered the monitor. If the monitor associated with objectref is not owned by any thread, the current thread becomes the owner of the monitor, setting the entry count of this monitor to 1.”
![Page 25: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/25.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 25
Atomics
2525
Atomics (like java.util.concurrent.atomic.AtomicLong)are implemented as native calls, they are hardware instructions.
![Page 26: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/26.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 26
Atomics Implementation
![Page 27: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/27.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted27
Atomics Hardware
• CAS (cmp&swap): when 2 processors access the same memory location, the machine “hangs” a memory for a moment for one processor to operate a memory exclusively (interrupts are waiting)
• Spinlock for SPARC-like architectures
![Page 28: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/28.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted28
Also….
Let’s skip, not wait, and:• atomics are all about skipping, • ‘synchronized’ are all about waiting
![Page 29: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/29.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 29
Self-Restriction #1
The wait-free pool never uses any synchronization primitive (including ‘synchronized’) but just atomic variables
![Page 30: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/30.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 3030
Self-Restriction #2
Bring the number of declared atomics variables to an absolute minimum
![Page 31: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/31.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 313131
Self-Restriction #3
Use only the wait-free pool locking mechanism for the rest of the pool:
The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000 lines of Java code, – not a single ‘synchronized’ keyword
![Page 32: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/32.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 323232
Problem
Requirements
How it works
Benchmark
Conclusion
3
2
5
4
1
![Page 33: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/33.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 33
Empty Pool
![Page 34: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/34.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 34
Create An Empty Slot
![Page 35: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/35.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 35
Reserve A Slot
![Page 36: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/36.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 36
Write A Data
![Page 37: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/37.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 37
Data Is Written
![Page 38: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/38.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 38
Release A Slot
![Page 39: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/39.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 39
Two Threads Write Data
![Page 40: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/40.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 40
Two Threads Write Data
![Page 41: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/41.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 41
Two Threads Write Data
![Page 42: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/42.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 42
Two Threads Write Data
![Page 43: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/43.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 43
Two Threads Write Data
![Page 44: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/44.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 44
Two Threads Write Data
![Page 45: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/45.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 45
Two Threads Write Data
![Page 46: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/46.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 46
Two Threads Write Data
![Page 47: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/47.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 47
Two Threads Write Data
![Page 48: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/48.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 48
Two Threads Write Data
![Page 49: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/49.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 49
Two Threads Write Data
![Page 50: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/50.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 50
Four Threads: Delete And Write Data
![Page 51: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/51.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 51
Four Threads: Delete And Write Data
![Page 52: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/52.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 52
Four Threads: Delete And Write Data
![Page 53: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/53.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 53
Four Threads: Delete And Write Data
![Page 54: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/54.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 54
Four Threads: Delete And Write Data
![Page 55: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/55.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 55
Four Threads: Delete And Write Data
![Page 56: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/56.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 56
Four Threads: Delete And Write Data
![Page 57: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/57.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 57
Two Threads: Revisiting
![Page 58: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/58.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 58
Five Slots Occupied, One Empty
![Page 59: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/59.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 595959
Problem
Requirements
How it works
Benchmark
Conclusion
4
2
3
5
1
![Page 60: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/60.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential – Internal/Restricted/Highly Restricted60
Benchmark
1. Many threads are running an iterative task concurrently (same task is running for many times within one thread)
2. Only 6 physical connections
3. A task consists of a pool’s borrow and a return operations
4. Oracle Enterpise Linux 5 Box with 4 CPUs (I tried 64), 100% CPU utilization
5. UCP 11.2.0.4 or ICC (later will show UCP 12.2)
![Page 61: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/61.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 61
Comparison Graphconcurrent sessions (THREADS) 10 50 100 500 1000 5000 10000
wait-free CP (borrows/sec) 368066 369876 370554 381744 381129 382482 384204
old style CP (borrows/sec) 178890 201743 173464 134211 89263 41362 15404
0
50000
100000
150000
200000
250000
300000
350000
400000
450000
10 50 100 500 1000 5000 10000
borr
ows/
sec
concurrent sessions (THREADS)
wait-free CP (borrows/sec)
old style CP (borrows/sec)
![Page 62: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/62.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 6262
Problem
Requirements
How it works
Benchmark
Conclusion5
2
3
4
1
![Page 63: Training On - Oracle Cloud · The core of Java Connection Pool functionality, highly concurrent logic, including complex mechanisms like fast failover and load balancing, over 17,000](https://reader034.vdocuments.mx/reader034/viewer/2022051809/60105c643835bb31b3247c65/html5/thumbnails/63.jpg)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 63
Conclusions
1. It is important not to use critical sections
2. It is important to use as less atomics as possible
3. It is important to use per-slot per-thread individual locking
4. We never wait to visit locked slot, but re-visit instead
5. Wait-free programming is challenging, but pays back