Last active
September 12, 2023 12:58
-
-
Save QAInsights/6c86b458f4ab4c02fb482f3af041fe81 to your computer and use it in GitHub Desktop.
Revisions
-
QAInsights revised this gist
Sep 12, 2023 . No changes.There are no files selected for viewing
-
QAInsights revised this gist
Sep 12, 2023 . 1 changed file with 32 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,35 +1,33 @@ import org.apache.http.client.methods.HttpGet import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients import org.apache.http.impl.conn.PoolingHttpClientConnectionManager import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy import org.apache.http.util.EntityUtils // Define the desired number of connections def maxConnectionsPerRoute = 1 def maxTotalConnections = 1 // Create a connection manager with the specified number of connections PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager() connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute) connectionManager.setMaxTotal(maxTotalConnections) //log.info("${connectionManager}") def customKeepAliveStrategy = new DefaultConnectionKeepAliveStrategy() { @Override public long getKeepAliveDuration(org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context) { // Set the keep-alive timeout to 60 seconds (in milliseconds) return 60 * 1000 } } //log.info("Keep-Alive Timeout: " + customKeepAliveStrategy.getKeepAliveDuration(null, null) + " milliseconds") // Create a HttpClient instance using the connection manager CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connectionManager) .setKeepAliveStrategy(customKeepAliveStrategy) @@ -40,19 +38,25 @@ vars.putObject("customHttpClient", httpClient) // Retrieve the custom HttpClient from the variable def customHttpClient = vars.getObject("customHttpClient") as CloseableHttpClient //log.info("${customHttpClient}") // Get the context's connection manager, which contains connection data //def cm = customHttpClient.getConnectionManager() // Create an HTTP request def httpGet = new HttpGet(args[0] + "://" + args[1]) // Execute the request using the custom HttpClient def response = customHttpClient.execute(httpGet) // Get the connection number for the executed request // Print the HTTP response content //log.info("Response Content:\n${EntityUtils.toString(response.getEntity())}") log.info("Active Connections: ${args[2]}" + connectionManager.getTotalStats().getLeased()) log.info("Available Connections: ${args[2]} " + connectionManager.getTotalStats().getAvailable()) response.close() // Close the response -
QAInsights revised this gist
Sep 12, 2023 . 1 changed file with 28 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,33 +1,35 @@ import org.apache.hc.core5.ssl.SSLContexts import org.apache.hc.core5.ssl.SSLContextBuilder import org.apache.hc.client5.HttpClients import org.apache.hc.core5.ssl.SSLConnectionSocketFactoryBuilder import org.apache.hc.core5.ssl.TrustSelfSignedStrategy import org.apache.hc.core5.ssl.PrivateKeyStrategy import org.apache.hc.core5.ssl.KeyStoreType import org.apache.hc.core5.ssl.SSLContext import org.apache.hc.core5.util.TimeValue import org.apache.hc.core5.pool.PoolStats import org.apache.hc.core5.ssl.SSLHost import org.apache.hc.core5.ssl.TLS import org.apache.hc.core5.ssl.PrivateKeyDetails import org.apache.hc.core5.ssl.KeyMaterial // Define the desired number of connections def maxConnectionsPerRoute = 1 def maxTotalConnections = 1 // Create a connection manager with the specified number of connections PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( 60, // Default connection time to live TimeValue.ofSeconds(60) // Validate after inactivity ) connectionManager.setMaxTotal(maxTotalConnections) connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute) // Create a custom keep-alive strategy def customKeepAliveStrategy = (response, context) -> 60 * 1000 // Set the keep-alive timeout to 60 seconds (in milliseconds) // Create an HttpClient instance CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connectionManager) .setKeepAliveStrategy(customKeepAliveStrategy) @@ -38,25 +40,19 @@ vars.putObject("customHttpClient", httpClient) // Retrieve the custom HttpClient from the variable def customHttpClient = vars.getObject("customHttpClient") as CloseableHttpClient // Create an HTTP request def httpGet = new HttpGet(args[0] + "://" + args[1]) // Execute the request using the custom HttpClient def response = customHttpClient.execute(httpGet) // Print the HTTP response content log.info("Response Content:\n${EntityUtils.toString(response.getEntity())}") // Get connection pool stats def poolStats = connectionManager.getTotalStats() log.info("Active Connections: ${args[2]}" + poolStats.getLeased()) log.info("Available Connections: ${args[2]} " + poolStats.getAvailable()) response.close() // Close the response -
QAInsights revised this gist
Sep 12, 2023 . 1 changed file with 14 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,10 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy import org.apache.http.util.EntityUtils // Define the desired number of connections def maxConnectionsPerRoute = 1 def maxTotalConnections = 1 // Create a connection manager with the specified number of connections PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager() @@ -22,6 +23,7 @@ def customKeepAliveStrategy = new DefaultConnectionKeepAliveStrategy() { return 60 * 1000 } } //log.info("Keep-Alive Timeout: " + customKeepAliveStrategy.getKeepAliveDuration(null, null) + " milliseconds") @@ -38,7 +40,7 @@ vars.putObject("customHttpClient", httpClient) def customHttpClient = vars.getObject("customHttpClient") as CloseableHttpClient //log.info("${customHttpClient}") // Get the context's connection manager, which contains connection data //def cm = customHttpClient.getConnectionManager() // Create an HTTP request def httpGet = new HttpGet(args[0] + "://" + args[1]) @@ -49,4 +51,12 @@ def response = customHttpClient.execute(httpGet) // Get the connection number for the executed request // Print the HTTP response content //log.info("Response Content:\n${EntityUtils.toString(response.getEntity())}") log.info("Active Connections: ${args[2]}" + connectionManager.getTotalStats().getLeased()) log.info("Available Connections: ${args[2]} " + connectionManager.getTotalStats().getAvailable()) response.close() // Close the response -
QAInsights revised this gist
Sep 10, 2023 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,8 @@ def customKeepAliveStrategy = new DefaultConnectionKeepAliveStrategy() { return 60 * 1000 } } //log.info("Keep-Alive Timeout: " + customKeepAliveStrategy.getKeepAliveDuration(null, null) + " milliseconds") // Create a HttpClient instance using the connection manager CloseableHttpClient httpClient = HttpClients.custom() -
QAInsights revised this gist
Sep 10, 2023 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,10 +15,18 @@ connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute) connectionManager.setMaxTotal(maxTotalConnections) //log.info("${connectionManager}") def customKeepAliveStrategy = new DefaultConnectionKeepAliveStrategy() { @Override public long getKeepAliveDuration(org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context) { // Set the keep-alive timeout to 60 seconds (in milliseconds) return 60 * 1000 } } // Create a HttpClient instance using the connection manager CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connectionManager) .setKeepAliveStrategy(customKeepAliveStrategy) .build() // Set the HttpClient as a variable to be used in the sampler -
QAInsights created this gist
Sep 10, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ import org.apache.http.client.methods.HttpGet import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients import org.apache.http.impl.conn.PoolingHttpClientConnectionManager import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy import org.apache.http.util.EntityUtils // Define the desired number of connections def maxConnectionsPerRoute = 10 def maxTotalConnections = 10 // Create a connection manager with the specified number of connections PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager() connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute) connectionManager.setMaxTotal(maxTotalConnections) //log.info("${connectionManager}") // Create a HttpClient instance using the connection manager CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connectionManager) .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()) .build() // Set the HttpClient as a variable to be used in the sampler vars.putObject("customHttpClient", httpClient) // Retrieve the custom HttpClient from the variable def customHttpClient = vars.getObject("customHttpClient") as CloseableHttpClient //log.info("${customHttpClient}") // Get the context's connection manager, which contains connection data def cm = customHttpClient.getConnectionManager() // Create an HTTP request def httpGet = new HttpGet(args[0] + "://" + args[1]) // Execute the request using the custom HttpClient def response = customHttpClient.execute(httpGet) // Get the connection number for the executed request // Print the HTTP response content //log.info("Response Content:\n${EntityUtils.toString(response.getEntity())}")