On Fri, 2013-05-03 at 08:14 -0400, Lance D. wrote:
> Hello,
> 
> I've got a question about Socket timeouts. I've got a program that must be
> single threaded.  I know that's got its own share of problems, but the
> biggest one that I have right now is the case of trying to connect to a
> broker on a host that doesn't exist.
> 
> I'll start with my configuration.  I have a client running with the 0.14
> API on a Redhat Linux OS.  My program uses a lookup service to find brokers
> and exchanges that are providing data.  The client connects to each
> exchange, pulls the data and disconnects.  I don't need to do this
> extremely quickly, but it really shouldn't take more than 1-2 seconds per
> connection because they are all on a small network.
> 
> My problems begin when the lookup service gives me a broker address for a
> host that is powered off.  When I call open on the connection, the SYN
> packet is sent and I'm stuck waiting for the kernel socket timeout to
> expire before qpid throws that exception.  That means that I'm stalled for
> 20 seconds for each down host.
> 
> So, my question to this wonderful group of users is this: what is the best
> way (other than going multi-threaded), to reduce my wait from 20 seconds
> down to 2 seconds?

Assumptions:
* You are using the C++ messaging API (namespace qpid::messaging)

I think you can solve this by setting the heartbeat timeout option on
the connection. If I remember correctly the client sets the heartbeat
timer before trying the connection so if it doesn't get a connection
within 2*heartbeat interval it will abort the connection.

For example using the qpid-send application:

  qpid-send -a foo -b example.com

Takes a long time to time out(your situation);

  qpid-send -a foo -b example.com -connection-options {heartbeat:1}

Times out in 2 seconds (or so):
  2013-05-03 16:55:27 [Network] warning Connect failed: Connection
timedout
  2013-05-03 16:55:27 [Client] warning Connection  closed
  qpid-send: Failed to connect (reconnect disabled)

programatically (untested snippets):
  connection = Connection(url, "{heartbeat:1}");
  connection.open();

Or
  connection.setOption("heartbeat", 1);
  connection.open();

Hope that helps.

Andrew



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to