From 931508d3e56fbd1e6e80c4939052c69affea1edb Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Fri, 25 Oct 2024 21:01:03 +0530 Subject: [PATCH 1/3] [Automated] Update native jar versions in toml files --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 35866741..7ef5595c 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -69,7 +69,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.11.3" +version = "2.11.4" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, From e954e7be3e8eee3ecb6118027962f724f6b11961 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 28 Oct 2024 17:33:58 +0530 Subject: [PATCH 2/3] Improve query performance --- .../sql/datasource/SQLWorkerThreadPool.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java b/native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java index 1eef3e20..b72287cc 100644 --- a/native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java +++ b/native/src/main/java/io/ballerina/stdlib/sql/datasource/SQLWorkerThreadPool.java @@ -20,6 +20,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -34,7 +35,8 @@ private SQLWorkerThreadPool() { // This is similar to cachedThreadPool util from Executors.newCachedThreadPool(..); but with upper cap on threads public static final ExecutorService SQL_EXECUTOR_SERVICE = new ThreadPoolExecutor(0, 50, - 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new SQLThreadFactory()); + 60L, TimeUnit.SECONDS, new BlockingTaskQueue(), new SQLThreadFactory(), + new RetryTaskRejectionPolicy()); static class SQLThreadFactory implements ThreadFactory { @Override @@ -44,4 +46,31 @@ public Thread newThread(Runnable r) { return ballerinaSql; } } + + static class BlockingTaskQueue extends LinkedBlockingQueue { + private static final long serialVersionUID = 1L; + + @Override + public boolean offer(Runnable task) { + // By returning false, we signal the ThreadPoolExecutor to bypass this queue and attempt to + // spawn a new thread if it hasn't reached the maximum pool size. This approach favors creating + // new threads over queuing tasks, thereby enabling more aggressive parallelism. + return false; + } + + public void retryTask(Runnable task) { + if (!super.offer(task)) { + throw new IllegalStateException("Falied to requeue task: " + task); + } + } + } + + static class RetryTaskRejectionPolicy implements RejectedExecutionHandler { + @Override + public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { + if (executor.getQueue() instanceof BlockingTaskQueue cbq) { + cbq.retryTask(task); + } + } + } } From d14943690bf0e43d296f9cbe7b2dfa8433cdd664 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Mon, 28 Oct 2024 19:42:35 +0530 Subject: [PATCH 3/3] [Automated] Update native jar versions in toml files --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 7ef5595c..2d2159b1 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -69,7 +69,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.11.4" +version = "2.11.5" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"},