Server connection - Best practices

  • 16 September 2008
  • 5 replies
  • 1 view

Badge +3

Hi

I created a singleton to use the smart object server. Its methods are OpenConnection and CloseConnection. But when i have many access to the server some bugs occur (Server not initialized).

So i want your opinion about best practices using server connection. Do you leave connection opened ?  In a web page i open a connection and close it in PageLoad method and open and close a new connection again in Submit method. Is it correct ? Access times are bad with this method.

 

Thank for your replies 


5 replies

Badge +9
In general I would recommend keeping the connection as short as possible.  i.e. Open, Execute, Close.  That has worked well in most cases.  Not too sure about keeping the connection open for long periods.  I would think you could hit issues like timeouts, connectivity breakages (e.g. network issues), etc.  This could cause quite a bit of headaches in properly maintaining the connection.
Badge +3

Thank you Johnny

I used a singleton because i thought that K2 connection manages a pool of connection. But i'm not sure.


Badge +9

From chatting with some of the guys, the K2server internally manages a pool of execution threads and of course on the DB end, SQL does the connection pooling.


 In terms of the connections, I think it's pretty light weight so there should not be significant performance impact with opening and closing.


 However, for batch jobs, you might want to utilize the same connection just to improve performance.  But you probably need some connection exception handling in the code to handle connecton breakages.  e.g. network switch fails.

Badge +3
Is it possible to configure the number of allowed connection in the connection pool ?
Badge +9

You can tune the number of worker threads on the K2Server end but generally this requires a bit of testing to tune it from the default settings.  Incorrect tuning might result in worse performance and/or deadlocks.


The settings are in the K2server.config file.

Reply