module Thrift::KeepAlive
Public Instance Methods
open()
click to toggle source
We'll override open
so that once the socket is opened we enable keepalive on it
Many queries are going to take a long time (10s of minutes) to complete and we don't want the connection to close while we wait for the query to return.
Unfortunately, Thrift
doesn't supply an easy way to get to the socket that it opens to communicate with Impala
.
I figured that while I was in here, monkey-patching a way to get to the socket, I might as well just enable keepalive here instead.
Calls superclass method
# File lib/impala/thrift_patch.rb 18 def open 19 super 20 s = @transport.handle 21 s.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_KEEPALIVE, true) 22 23 # Apparently Mac OS X (Darwin) doesn't implement the SOL_TCP options below 24 # so we'll hope keep alive works under Mac OS X, but in production 25 # we Dockerize Jigsaw, so these options should be available when 26 # we're running on Linux 27 if defined? ::Socket::SOL_TCP 28 s.setsockopt(::Socket::SOL_TCP, ::Socket::TCP_KEEPIDLE, 60) 29 s.setsockopt(::Socket::SOL_TCP, ::Socket::TCP_KEEPINTVL, 10) 30 s.setsockopt(::Socket::SOL_TCP, ::Socket::TCP_KEEPCNT, 5) 31 end 32 end