Thread: support for keep alive option

support for keep alive option

From
PG User
Date:
Hi,
I looking at code and found that there is an option for tpch keep alive in jdbc driver but there is no such support in odbc driver.
Is there any plan to support that in near future?

Thanking you.

- pguser

Re: support for keep alive option

From
PG User
Date:
Hi Barry,
Thank you for reply.
I am little bit confused.

I saw the code for JDBC code and it sets true to
newStream.getSocket().setKeepAlive(requireTCPKeepAlive);
if ?tchKeepAlive=true is given.


But, in socket.c of odbc driver, in  
char
SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname, long timeout)

Can we just do the same thing?:
setsockopt(self->socket, IPPROTO_TCP, TCP_KEEPALIVE, (char *) &i, len);

as did in the same function:

if (setsockopt(self->socket, IPPROTO_TCP, TCP_NODELAY, (char *) &i, len) < 0) { SOCK_set_error(self, SOCKET_COULD_NOT_CONNECT, "Could not set socket to NODELAY."); closesocket(self->socket); self->socket = (SOCKETFD) -1; return 0; }

- Nachiket


On Tue, Dec 17, 2013 at 1:29 PM, Barry Bell <Barry.Bell@hartehanks.com> wrote:

The “keep alive” option is set inside the client, not the driver,

What ever programing language you are using may have a keep alive ( and timeout settings) for the OBDC driver.

 

Barry Bell

Senior Developer/Analyst, Harte Hanks Logsitics

Harte Hanks, Inc.

 

Office: 954-429-3771 Ext 267 Barry.Bell@hartehanks.com

1525 NW 3rd ST, Deerfield Beach, FL 33442

 

 

 

www.hartehanks.com

 

 

 

From: pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of PG User
Sent: Tuesday, December 17, 2013 4:27 PM
To: pgsql-odbc@postgresql.org
Subject: [ODBC] support for keep alive option

 

Hi,

I looking at code and found that there is an option for tpch keep alive in jdbc driver but there is no such support in odbc driver.

Is there any plan to support that in near future?

 

Thanking you.

 

- pguser


Attachment

Re: support for keep alive option

From
PG User
Date:
Hi Barry,
I changed the code and tested it and keep alive option is working fine for me now.
Is this patch ok to add to postgres odbc driver?

The patch is very simple as follows:

diff --git a/socket.c b/socket.c
index 2e3e1cc..ac17b4d 100644
--- a/socket.c
+++ b/socket.c
@@ -330,6 +330,19 @@ retry:
         fcntl(self->socket, F_SETFL, O_NONBLOCK);
 #endif

+       {
+               int optval;
+               socklen_t optlen;
+               optval=1;
+               optlen = sizeof(optval);
+
+               if(setsockopt(self->socket, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0)
+               {
+                       SOCK_set_error(self, SOCKET_COULD_NOT_CONNECT, "Could not set socket to SO_KEEPALIVE.");
+                       goto cleanup;
+               }
+       }
+
        if (curadr)
        {
                struct sockaddr *in = (struct sockaddr *) &(self->sadr_area);





On Tue, Dec 17, 2013 at 3:25 PM, PG User <pguser1982@gmail.com> wrote:
Hi Barry,
Thank you for reply.
I am little bit confused.

I saw the code for JDBC code and it sets true to
newStream.getSocket().setKeepAlive(requireTCPKeepAlive);
if ?tchKeepAlive=true is given.


But, in socket.c of odbc driver, in  
char
SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname, long timeout)

Can we just do the same thing?:
setsockopt(self->socket, IPPROTO_TCP, TCP_KEEPALIVE, (char *) &i, len);

as did in the same function:

if (setsockopt(self->socket, IPPROTO_TCP, TCP_NODELAY, (char *) &i, len) < 0) { SOCK_set_error(self, SOCKET_COULD_NOT_CONNECT, "Could not set socket to NODELAY."); closesocket(self->socket); self->socket = (SOCKETFD) -1; return 0; }

- Nachiket


On Tue, Dec 17, 2013 at 1:29 PM, Barry Bell <Barry.Bell@hartehanks.com> wrote:

The “keep alive” option is set inside the client, not the driver,

What ever programing language you are using may have a keep alive ( and timeout settings) for the OBDC driver.

 

Barry Bell

Senior Developer/Analyst, Harte Hanks Logsitics

Harte Hanks, Inc.

 

Office: 954-429-3771 Ext 267 Barry.Bell@hartehanks.com

1525 NW 3rd ST, Deerfield Beach, FL 33442

 

 

 

www.hartehanks.com

 

 

 

From: pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of PG User
Sent: Tuesday, December 17, 2013 4:27 PM
To: pgsql-odbc@postgresql.org
Subject: [ODBC] support for keep alive option

 

Hi,

I looking at code and found that there is an option for tpch keep alive in jdbc driver but there is no such support in odbc driver.

Is there any plan to support that in near future?

 

Thanking you.

 

- pguser



Attachment

Re: support for keep alive option

From
"Inoue, Hiroshi"
Date:
Hi Barry,

Sorry for the late reply.

(2014/01/02 23:02), Barry Bell wrote:
> Thanks, Alright with me to add the patch in
>
> But you may want to Hiroshi (He does the office and unofficial ODBC
> driver releases),
>
> Hiroshi, what do you think of this?

OK I would introduce the functionality.

Thanks.
Hiroshi Inoue


--
I am using the free version of SPAMfighter.
SPAMfighter has removed 2543 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

Do you have a slow PC? Try a Free scan
http://www.spamfighter.com/SLOW-PCfighter?cid=sigen



Re: support for keep alive option

From
Heikki Linnakangas
Date:
On 01/08/2014 01:48 AM, Inoue, Hiroshi wrote:
> Hi Barry,
>
> Sorry for the late reply.
>
> (2014/01/02 23:02), Barry Bell wrote:
>> Thanks, Alright with me to add the patch in
>>
>> But you may want to Hiroshi (He does the office and unofficial ODBC
>> driver releases),
>>
>> Hiroshi, what do you think of this?
>
> OK I would introduce the functionality.

I don't think it should be enabled by default. It's common to expose
keepalive and other TCP settings as an option, like libpq does, but it's
not usually enabled by default, and it might be an unwelcome surprise to
some existing applications.

In particular, if you have a dialup connection, you do *not* want an
idle connection to keep sending periodic keep-alives, because keeping
the connection open costs money. It's not as big a problem these days as
it used to be, but still.

- Heikki


Re: support for keep alive option

From
Hiroshi Inoue
Date:
(2014/01/08 18:20), Heikki Linnakangas wrote:
> On 01/08/2014 01:48 AM, Inoue, Hiroshi wrote:
>> Hi Barry,
>>
>> Sorry for the late reply.
>>
>> (2014/01/02 23:02), Barry Bell wrote:
>>> Thanks, Alright with me to add the patch in
>>>
>>> But you may want to Hiroshi (He does the office and unofficial ODBC
>>> driver releases),
>>>
>>> Hiroshi, what do you think of this?
>>
>> OK I would introduce the functionality.
>
> I don't think it should be enabled by default. It's common to expose
> keepalive and other TCP settings as an option, like libpq does, but it's
> not usually enabled by default, and it might be an unwelcome surprise to
> some existing applications.
>
> In particular, if you have a dialup connection, you do *not* want an
> idle connection to keep sending periodic keep-alives, because keeping
> the connection open costs money. It's not as big a problem these days as
> it used to be, but still.

Libpq's keepalives option is on by default. So currently psqlodbc's
keepalive is enabled when libpq is used(in case ssl used etc) otherwise
it is disabled.
Though I am about to enable keepalive by default, I'm not sure which
  should be the default.

regards,
Hiroshi Inoue




Re: support for keep alive option

From
Heikki Linnakangas
Date:
On 01/08/2014 01:40 PM, Hiroshi Inoue wrote:
> (2014/01/08 18:20), Heikki Linnakangas wrote:
>> I don't think it should be enabled by default. It's common to expose
>> keepalive and other TCP settings as an option, like libpq does, but it's
>> not usually enabled by default, and it might be an unwelcome surprise to
>> some existing applications.
>>
>> In particular, if you have a dialup connection, you do *not* want an
>> idle connection to keep sending periodic keep-alives, because keeping
>> the connection open costs money. It's not as big a problem these days as
>> it used to be, but still.
>
> Libpq's keepalives option is on by default.

Oh, I didn't realize that.

> So currently psqlodbc's
> keepalive is enabled when libpq is used(in case ssl used etc) otherwise
> it is disabled.
> Though I am about to enable keepalive by default, I'm not sure which
>   should be the default.

I guess it would be best to enable it by default in psqlodbc as well, then.

- Heikki


Re: support for keep alive option

From
PG User
Date:
Hi All,
Thank you very much for your thoughts and discussions.

I need a last favor:
Is it possible for you to add functionality to postgres odbc version 9.x (latest) as well as 8.4.2?

Thanking you.

- Nachiket


On Wed, Jan 8, 2014 at 4:06 AM, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
On 01/08/2014 01:40 PM, Hiroshi Inoue wrote:
(2014/01/08 18:20), Heikki Linnakangas wrote:
I don't think it should be enabled by default. It's common to expose
keepalive and other TCP settings as an option, like libpq does, but it's
not usually enabled by default, and it might be an unwelcome surprise to
some existing applications.

In particular, if you have a dialup connection, you do *not* want an
idle connection to keep sending periodic keep-alives, because keeping
the connection open costs money. It's not as big a problem these days as
it used to be, but still.

Libpq's keepalives option is on by default.

Oh, I didn't realize that.


So currently psqlodbc's
keepalive is enabled when libpq is used(in case ssl used etc) otherwise
it is disabled.
Though I am about to enable keepalive by default, I'm not sure which
  should be the default.

I guess it would be best to enable it by default in psqlodbc as well, then.

- Heikki

Re: support for keep alive option

From
PG User
Date:
Do we know when the patch will be available in postgres odbc code for mentioned versions?

Thanking you.

- Nachiket


On Wed, Jan 8, 2014 at 11:12 AM, PG User <pguser1982@gmail.com> wrote:
Hi All,
Thank you very much for your thoughts and discussions.

I need a last favor:
Is it possible for you to add functionality to postgres odbc version 9.x (latest) as well as 8.4.2?

Thanking you.

- Nachiket


On Wed, Jan 8, 2014 at 4:06 AM, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:
On 01/08/2014 01:40 PM, Hiroshi Inoue wrote:
(2014/01/08 18:20), Heikki Linnakangas wrote:
I don't think it should be enabled by default. It's common to expose
keepalive and other TCP settings as an option, like libpq does, but it's
not usually enabled by default, and it might be an unwelcome surprise to
some existing applications.

In particular, if you have a dialup connection, you do *not* want an
idle connection to keep sending periodic keep-alives, because keeping
the connection open costs money. It's not as big a problem these days as
it used to be, but still.

Libpq's keepalives option is on by default.

Oh, I didn't realize that.


So currently psqlodbc's
keepalive is enabled when libpq is used(in case ssl used etc) otherwise
it is disabled.
Though I am about to enable keepalive by default, I'm not sure which
  should be the default.

I guess it would be best to enable it by default in psqlodbc as well, then.

- Heikki


Re: support for keep alive option

From
"Inoue, Hiroshi"
Date:
(2014/01/14 6:02), PG User wrote:
> Do we know when the patch will be available in postgres odbc code for
> mentioned versions?

I pushd the change to set TCP keepalive by default.

regards,
Hiroshi Inoue

--
I am using the free version of SPAMfighter.
SPAMfighter has removed 2897 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

Do you have a slow PC? Try a Free scan
http://www.spamfighter.com/SLOW-PCfighter?cid=sigen



Re: support for keep alive option

From
PG User
Date:
Hi Hiroshi,
Thank you for mail.

I see new code in git repo.
This change will go to 8.4.2 as well, right?

Thank you.

- Nachiket


On Tue, Jan 14, 2014 at 4:20 PM, Inoue, Hiroshi <inoue@tpf.co.jp> wrote:
(2014/01/14 6:02), PG User wrote:
Do we know when the patch will be available in postgres odbc code for
mentioned versions?

I pushd the change to set TCP keepalive by default.

regards,

Hiroshi Inoue

--
I am using the free version of SPAMfighter.
SPAMfighter has removed 2897 of my spam emails to date.

Get the free SPAMfighter here: http://www.spamfighter.com/len

Do you have a slow PC? Try a Free scan http://www.spamfighter.com/SLOW-PCfighter?cid=sigen


Re: support for keep alive option

From
Hiroshi Inoue
Date:
(2014/01/21 9:31), PG User wrote:
> Hi Hiroshi,
> Thank you for mail.
>
> I see new code in git repo.
> This change will go to 8.4.2 as well, right?

No.
Please upgrade to the next version.

regards,
Hiroshi Inoue