I am creating a jdbc object in spark driver and I am using that in executor to access the db. So my concern is that is it the same connection object or executors would get a copy of connection object so there would be separate connection per partition?
            Asked
            
        
        
            Active
            
        
            Viewed 596 times
        
    2
            
            
        - 
                    Did answer help? – thebluephantom Mar 21 '22 at 06:17
 
1 Answers
1
            - In Scala - not that you state if pyspark, Java or Scala,
- you can create an 
Objectfor aConnectionPoolas per link below;- this will be instantiated for each 
Executorand shared byCorescomprising thatExecutor. I.e. not as a Singleton for all foreachPartition.- Your concern / question is addressed in the previous bullet, i.e. their own Connections.
 
 
 - this will be instantiated for each 
 
 - you can create an 
 
See https://medium.com/@ravishankar.nair/implementing-a-connectionpool-in-apache-sparks-foreachpartition-4add46dc8ae2. It's a good reference from medium.com.
        thebluephantom
        
- 16,458
 - 8
 - 40
 - 83