web stats
Connection pooling - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 02-25-2020, 12:57 AM
usuariousuario usuariousuario is offline
Mirth Newb
Join Date: Sep 2016
Location: Madrid, Spain
Posts: 12
usuariousuario is on a distinguished road
Default Connection pooling

Right now whenever I need to make a database call in javascript transformer I use the DatabaseConnectionFactory.createConnection method to obtain a connection. It works great but it is not the optimal way. I would like to use a connection pool.

This is now the deploy script of a channel which get connections from database in its javascript code

// __________________________________________________________________________________________
var hikariConfig = new Packages.com.zaxxer.hikari.HikariConfig();

hikariConfig.setJdbcUrl(' **** ');
hikariConfig.setDriverClassName(' **** ');

	// this is just configuration stuff. Do not pay much attention to the values as they are not production used, just for testing
hikariConfig.setIdleTimeout( Packages.java.util.concurrent.TimeUnit.MINUTES.toMillis(1) );

var hikariDataSource = new Packages.com.zaxxer.hikari.HikariDataSource(hikariConfig);

$gc('ds', hikariDataSource);
// __________________________________________________________________________________________
And the undeploy

// __________________________________________________________________________________________
// __________________________________________________________________________________________

Whenever in the javascript code from the channel, the connections are now retrieved like this
conection = $gc('ds').getConnection(); // with pool
Instead of the previus way
conection = DatabaseConnectionFactory.createConnection(..., ..., ..., ...);   // without pool
The channel does not work in parallel. Now it can process the same amount of messages in 30% of the time, which is just great.

As this is per channel, if a undeploy a channel, the connections are drop off. If I deploy it again, the connections are created. But this configuration per channel. However I would like to achieve this not per channel but globally, at somehow mirth instance level.

So I am thinking about moving the code from before to the global script scripts. But there are some things which I am worried about.
  • If a undeploy a single channel the code in the rest of the channels will fail, as all the connections are now closed.
  • If a deploy a single channel, the connections are all closed first and then recreated. In the meantime, another channel may try to acquire a connection and fail.

I can omit the undeploy part, and control in the deploy if there is a pool already created. But in that case the pool is created at the first deploy of the start of the Mirth instance and there is no way to refresh or change it while the service is running. But I think this last part is impossible to achieve anyway.
  • Is there a place in Mirth where I can deploy this better than the global scripts.
  • Any advice on how to correctly code this ?
* Is there a place in Mirth where I can deploy this better than the global scripts.
* Any advice on how to correctly code this ?

Thank you very much in advance.
Reply With Quote

connection, pool

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 11:53 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation