Skip to content

Commit 3d0eec0

Browse files
committed
fix: Scheduling synchronized block on bounded elastic threadpool instead of main event threadpool (#32343)
… ## Description > [!TIP] > _Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content team)._ > > _Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR._ Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Sanity" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!IMPORTANT] > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/8523943321> > Commit: `03dc817039ee24159438e613320550620353a2b7` > Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8523943321&attempt=1" target="_blank">Click here!</a> > All cypress tests have passed 🎉🎉🎉 <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved backend scheduling for datasource operations to enhance performance without blocking the main thread. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 24bcef9 commit 3d0eec0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.beans.factory.annotation.Autowired;
2525
import org.springframework.context.annotation.Lazy;
2626
import reactor.core.publisher.Mono;
27+
import reactor.core.scheduler.Schedulers;
2728

2829
import java.time.Instant;
2930
import java.util.Map;
@@ -103,7 +104,8 @@ public Mono<? extends DatasourceContext<?>> getCachedDatasourceContextMono(
103104
// Basically remove entry from both cache maps
104105
pluginExecutor.datasourceDestroy(connection);
105106
} catch (Exception e) {
106-
log.info("Error destroying stale datasource connection", e);
107+
log.info(
108+
Thread.currentThread().getName() + ": Error destroying stale datasource connection", e);
107109
}
108110
}
109111
datasourceContextMonoMap.remove(datasourceContextIdentifier);
@@ -117,7 +119,8 @@ public Mono<? extends DatasourceContext<?>> getCachedDatasourceContextMono(
117119
*/
118120
if (datasourceContextIdentifier.getDatasourceId() != null
119121
&& datasourceContextMonoMap.get(datasourceContextIdentifier) != null) {
120-
log.debug("Cached resource context mono exists. Returning the same.");
122+
log.debug(Thread.currentThread().getName()
123+
+ ": Cached resource context mono exists. Returning the same.");
121124
return datasourceContextMonoMap.get(datasourceContextIdentifier);
122125
}
123126

@@ -182,11 +185,11 @@ public Mono<Object> updateDatasourceAndSetAuthentication(Object connection, Data
182185

183186
protected Mono<DatasourceContext<?>> createNewDatasourceContext(
184187
DatasourceStorage datasourceStorage, DatasourceContextIdentifier datasourceContextIdentifier) {
185-
log.debug("Datasource context doesn't exist. Creating connection.");
188+
log.debug(Thread.currentThread().getName() + ": Datasource context doesn't exist. Creating connection.");
186189
Mono<Plugin> pluginMono =
187190
pluginService.findById(datasourceStorage.getPluginId()).cache();
188191

189-
return pluginMono
192+
return (Mono<DatasourceContext<?>>) pluginMono
190193
.zipWith(pluginExecutorHelper.getPluginExecutor(pluginMono))
191194
.flatMap(tuple2 -> {
192195
Plugin plugin = tuple2.getT1();
@@ -214,7 +217,9 @@ protected Mono<DatasourceContext<?>> createNewDatasourceContext(
214217

215218
return getCachedDatasourceContextMono(
216219
datasourceStorage, plugin, pluginExecutor, monitor, datasourceContextIdentifier);
217-
});
220+
})
221+
// Scheduling on bounded elastic to avoid blocking the main thread
222+
.subscribeOn(Schedulers.boundedElastic());
218223
}
219224

220225
public boolean getIsStale(

0 commit comments

Comments
 (0)