From 45e4336d3cd2cfb981c4f8ea0774c5a8e130cc00 Mon Sep 17 00:00:00 2001 From: Jose Alberto Guerra Ugalde Date: Fri, 15 Nov 2024 03:36:21 -0600 Subject: [PATCH] =?UTF-8?q?-=20VERSION=204.11.14=20-=20Se=20agreg=C3=B3=20?= =?UTF-8?q?el=20parametro=20"setMaxPoolSize=3D5"=20para=20que=20solo=20gen?= =?UTF-8?q?ere=205=20conexiones=20a=20la=20base=20de=20datos,=20antes=20ge?= =?UTF-8?q?neraba=2015.=20-=20Se=20quitaron=20lineas=20previamente=20comen?= =?UTF-8?q?tadas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB1Handler.bas | 27 +++++++++--------- DB2Handler.bas | 1 - DB3Handler.bas | 1 - DB4Handler.bas | 1 - RDCConnector.bas | 67 +++++++++++++++++++++++++++++++++++++-------- jRDC_Multi.b4j | 22 +++++---------- jRDC_Multi.b4j.meta | 10 +++---- 7 files changed, 81 insertions(+), 48 deletions(-) diff --git a/DB1Handler.bas b/DB1Handler.bas index 40d2772..901e9cf 100644 --- a/DB1Handler.bas +++ b/DB1Handler.bas @@ -23,34 +23,33 @@ End Sub Sub Handle(req As ServletRequest, resp As ServletResponse) Log("********************* DB1 ********************") Dim start As Long = DateTime.Now - Dim q As String + Dim q As String Dim in As InputStream = req.InputStream Dim method As String = req.GetParameter("method") Connector = Main.Connectors.Get("DB1") Dim con As SQL Try con = Connector.GetConnection("DB1") -' con = Main.rdcConnectorDB1.GetConnection("") If method = "query2" Then q = ExecuteQuery2("DB1", con, in, resp) - '#if VERSION1 + '#if VERSION1 Else if method = "query" Then in = cs.WrapInputStream(in, "gzip") q = ExecuteQuery("DB1", con, in, resp) Else if method = "batch" Then in = cs.WrapInputStream(in, "gzip") q = ExecuteBatch("DB1", con, in, resp) - '#end if + '#end if Else if method = "batch2" Then q = ExecuteBatch2("DB1", con, in, resp) Else Log("Unknown method: " & method) resp.SendError(500, "unknown method") End If -Catch -Log(LastException) -resp.SendError(500, LastException.Message) -End Try + Catch + Log(LastException) + resp.SendError(500, LastException.Message) + End Try If con <> Null And con.IsInitialized Then con.Close Log($"Command: ${q}, took: ${DateTime.Now - start}ms, client=${req.RemoteAddress}"$) End Sub @@ -154,11 +153,11 @@ Private Sub ExecuteBatch(DB As String, con As SQL, in As InputStream, resp As Se WriteInt(r, out) Next out.Close -Catch -con.Rollback -Log(LastException) -resp.SendError(500, LastException.Message) -End Try + Catch + con.Rollback + Log(LastException) + resp.SendError(500, LastException.Message) + End Try Return $"batch (size=${numberOfStatements})"$ End Sub @@ -237,7 +236,7 @@ Private Sub WriteObject(o As Object, out As OutputStream) Else If GetType(o) = "[B" Then data = o out.WriteBytes(Array As Byte(T_BLOB), 0, 1) - WriteInt(data.Length, out) + WriteInt(data.Length, out) Else 'If o Is String Then (treat all other values as string) out.WriteBytes(Array As Byte(T_STRING), 0, 1) data = bc.StringToBytes(o, "UTF8") diff --git a/DB2Handler.bas b/DB2Handler.bas index 6b0d5c4..5566f39 100644 --- a/DB2Handler.bas +++ b/DB2Handler.bas @@ -30,7 +30,6 @@ Sub Handle(req As ServletRequest, resp As ServletResponse) Dim con As SQL Try con = Connector.GetConnection("DB2") -' con = Main.rdcConnectorDB2.GetConnection("DB2") If method = "query2" Then q = ExecuteQuery2("DB2", con, in, resp) '#if VERSION1 diff --git a/DB3Handler.bas b/DB3Handler.bas index b837ad3..e07a2dc 100644 --- a/DB3Handler.bas +++ b/DB3Handler.bas @@ -29,7 +29,6 @@ Sub Handle(req As ServletRequest, resp As ServletResponse) Connector = Main.Connectors.Get("DB3") Dim con As SQL Try -' con = Main.rdcConnectorDB3.GetConnection("DB3") con = Connector.GetConnection("DB3") If method = "query2" Then q = ExecuteQuery2("DB3", con, in, resp) diff --git a/DB4Handler.bas b/DB4Handler.bas index c832ae5..bc2ea24 100644 --- a/DB4Handler.bas +++ b/DB4Handler.bas @@ -29,7 +29,6 @@ Sub Handle(req As ServletRequest, resp As ServletResponse) Connector = Main.Connectors.Get("DB4") Dim con As SQL Try -' con = Main.rdcConnectorDB4.GetConnection("DB4") con = Connector.GetConnection("DB4") If method = "query2" Then q = ExecuteQuery2("DB4", con, in, resp) diff --git a/RDCConnector.bas b/RDCConnector.bas index 299fae4..a5fb232 100644 --- a/RDCConnector.bas +++ b/RDCConnector.bas @@ -17,12 +17,64 @@ End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize(DB As String) ' Log("RDCConnector Initialize") - If DB.EqualsIgnoreCase("DB1") Then DB = "" 'Esto para el config.properties or default -' If DB.EqualsIgnoreCase("DB1") Then DB = "" 'Esto para el config.properties or default + If DB.EqualsIgnoreCase("DB1") Then DB = "" 'Esto para el config.properties por default Dim config As Map = LoadConfigMap(DB) Log($"Inicializamos ${DB}, usuario: ${config.Get("User")}"$) - pool.Initialize(config.Get("DriverClass"), config.Get("JdbcUrl"), config.Get("User"), _ - config.Get("Password")) + pool.Initialize(config.Get("DriverClass"), config.Get("JdbcUrl"), config.Get("User"), config.Get("Password")) + Dim jo As JavaObject = pool + jo.RunMethod("setMaxPoolSize", Array(5)) 'number of concurrent connections + +' com.mchange.v2.c3p0.ComboPooledDataSource [ +' acquireIncrement -> 3, +' acquireRetryAttempts -> 30, +' acquireRetryDelay -> 1000, +' autoCommitOnClose -> False, +' automaticTestTable -> Null, +' breakAfterAcquireFailure -> False, +' checkoutTimeout -> 20000, +' connectionCustomizerClassName -> Null, +' connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, +' contextClassLoaderSource -> caller, +' dataSourceName -> 2rvxvdb7cyxd8zlw6dyb|63021689, +' debugUnreturnedConnectionStackTraces -> False, +' description -> Null, +' driverClass -> oracle.jdbc.driver.OracleDriver, +' extensions -> {}, +' factoryClassLocation -> Null, +' forceIgnoreUnresolvedTransactions -> False, +' forceSynchronousCheckins -> False, +' forceUseNamedDriverClass -> False, +' identityToken -> 2rvxvdb7cyxd8zlw6dyb|63021689, +' idleConnectionTestPeriod -> 600, +' initialPoolSize -> 3, +' jdbcUrl -> jdbc:oracle:thin:@//10.0.0.110:1521/DBKMT, +' maxAdministrativeTaskTime -> 0, +' maxConnectionAge -> 0, +' maxIdleTime -> 1800, +' maxIdleTimeExcessConnections -> 0, +' maxPoolSize -> 5, +' maxStatements -> 150, +' maxStatementsPerConnection -> 0, +' minPoolSize -> 3, +' numHelperThreads -> 3, +' preferredTestQuery -> DBMS_SESSION.SET_IDENTIFIER('whatever'), +' privilegeSpawnedThreads -> False, +' properties -> {password=******, user=******}, +' propertyCycle -> 0, +' statementCacheNumDeferredCloseThreads -> 0, +' testConnectionOnCheckin -> False, +' testConnectionOnCheckout -> True, +' unreturnedConnectionTimeout -> 0, +' userOverrides -> {}, +' usesTraditionalReflectiveProxies -> False +' ] + +' Dim jo2 As JavaObject = pool +' Log(jo2.GetField("END_TO_END_CLIENTID_INDEX")) + + jo.RunMethod("setPreferredTestQuery", Array("BEGIN DBMS_SESSION.SET_IDENTIFIER('whatever'); END;")) +' jo.RunMethod("setPreferredTestQuery", Array("alter session set current_schema=MYSCHEMA")) +' jo2.RunMethod("setClientIdentifier",Array( "MAX")) ' Tiempo máximo de inactividad antes de cerrar una conexión #if DEBUG DebugQueries = True #else @@ -33,13 +85,6 @@ Public Sub Initialize(DB As String) LoadSQLCommands(config, DB) End Sub -'Sub closePool -' If pool.GetConnection.IsInitialized Then -' pool.ClosePool -' Log("----- Cerramos pool") -' End If -'End Sub - Private Sub LoadConfigMap(DB As String) As Map Private DBX As String = "" If DB <> "" Then DBX = "." & DB diff --git a/jRDC_Multi.b4j b/jRDC_Multi.b4j index 287f9ff..7257669 100644 --- a/jRDC_Multi.b4j +++ b/jRDC_Multi.b4j @@ -28,7 +28,7 @@ Version=10 #Region Project Attributes #CommandLineArgs: #MergeLibraries: True - ' VERSION 4.11.09 + ' VERSION 4.11.14 '########################################################################################################### '###################### PULL ############################################################# 'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=git&Args=pull @@ -48,10 +48,6 @@ Version=10 Sub Process_Globals Public srvr As Server -' Public rdcConnectorDB1 As RDCConnector -' Public rdcConnectorDB2 As RDCConnector -' Public rdcConnectorDB3 As RDCConnector -' Public rdcConnectorDB4 As RDCConnector Public const VERSION As Float = 2.23 Type DBCommand (Name As String, Parameters() As Object) Type DBResult (Tag As Object, Columns As Map, Rows As List) @@ -65,7 +61,6 @@ Sub AppStart (Args() As String) srvr.Initialize("") Dim con As RDCConnector Connectors = srvr.CreateThreadSafeMap -' commandsMap = srvr.CreateThreadSafeMap commandsMap.Initialize con.Initialize("DB1") 'Inicializamos el default de config.properties Connectors.Put("DB1", con) @@ -75,31 +70,28 @@ Sub AppStart (Args() As String) If cpFiles.Size > 0 Then Log(cpFiles) For i = 0 To cpFiles.Size - 1 - If cpFiles.Get(i) = "config.DB2.properties" Then + If cpFiles.Get(i) = "config.DB2.properties" Then ' Si existe el archivo DB2, lo usamos. Dim con As RDCConnector con.Initialize("DB2") Connectors.Put("DB2", con) listaDeCP.Add("DB2") End If - If cpFiles.Get(i) = "config.DB3.properties" Then + If cpFiles.Get(i) = "config.DB3.properties" Then ' Si existe el archivo DB3, lo usamos. Dim con As RDCConnector con.Initialize("DB3") Connectors.Put("DB3", con) listaDeCP.Add("DB3") End If - If cpFiles.Get(i) = "config.DB4.properties" Then + If cpFiles.Get(i) = "config.DB4.properties" Then ' Si existe el archivo DB4, lo usamos. con.Initialize("DB4") Connectors.Put("DB4", con) listaDeCP.Add("DB4") - End If + End If Next End If -' con.Initialize("DB1") 'Inicializamos el default de config.properties -' Connectors.Put("DB1", con) -' srvr.Port = con.serverPort - srvr.AddHandler("/test", "TestHandler", False) + srvr.AddHandler("/test", "TestHandler", False) ' Agrega un manejador a la ruta "/test", asignando las solicitudes a la clase TestHandler, el último parámetro indica si el manejador debe ejecutar en un nuevo hilo (False en este caso) srvr.AddHandler("/manager", "Manager", False) - srvr.AddHandler("/*", "DB1Handler", False) + srvr.AddHandler("/*", "DB1Handler", False) ' Si no se especifica una base de datos, entonces asignamos la solicitud a la DB1. srvr.AddHandler("/db1", "DB1Handler", False) srvr.AddHandler("/DB1", "DB1Handler", False) srvr.AddHandler("/db2", "DB2Handler", False) diff --git a/jRDC_Multi.b4j.meta b/jRDC_Multi.b4j.meta index bf474b5..c316488 100644 --- a/jRDC_Multi.b4j.meta +++ b/jRDC_Multi.b4j.meta @@ -17,14 +17,14 @@ ModuleBreakpoints6= ModuleBreakpoints7= ModuleBreakpoints8= ModuleClosedNodes0= -ModuleClosedNodes1=9,10,11,12,13,14,15 -ModuleClosedNodes2=9,10,11,12,13,14,15 -ModuleClosedNodes3=8,9,10,11,12,13,14,15 -ModuleClosedNodes4=8,9,10,11,12,13,14,15 +ModuleClosedNodes1= +ModuleClosedNodes2= +ModuleClosedNodes3= +ModuleClosedNodes4= ModuleClosedNodes5= ModuleClosedNodes6= ModuleClosedNodes7= ModuleClosedNodes8= -NavigationStack=RDCConnector,Class_Globals,4,0,RDCConnector,GetConnection,60,0,RDCConnector,LoadConfigMap,39,0,RDCConnector,Initialize,19,6,DB1Handler,ExecuteBatch,145,0,DB1Handler,Handle,17,0,RDCConnector,GetCommand,52,6,RDCConnector,LoadSQLCommands,66,6,Main,AppStart,28,6,Main,Process_Globals,14,0 +NavigationStack=RDCConnector,LoadSQLCommands,120,6,RDCConnector,Initialize,21,6,Main,Process_Globals,28,0,DB1Handler,Class_Globals,8,0,DB1Handler,ReadList,312,0,Main,AppStart,81,6,DB2Handler,ReadList,312,0,DB3Handler,Class_Globals,11,0,DB3Handler,ReadList,312,0,DB3Handler,ReadBytesFully,277,0,DB4Handler,ReadList,312,0 SelectedBuild=0 VisibleModules=1,2,3,4,7,6,8