Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ping interval and max pings out #697

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,8 @@ Streaming Server Options:
-hbf, --hb_fail_count <int> Number of failed heartbeats before server closes the client connection
--ft_group <string> Name of the FT Group. A group can be 2 or more servers with a single active server and all sharing the same datastore.
-sl, --signal <signal>[=<pid>] Send signal to nats-streaming-server process (stop, quit, reopen)
-npi, --nc_ping_interval <uint> NATS Client ping interval in seconds. If not informed, NATS Streaming considers the NATS Client default value.
-npo, --nc_max_pings_out <int> NATS Client max pings out. If not informed, NATS Streaming considers the NATS Client default value.

Streaming Server Clustering Options:
--clustered <bool> Run the server in a clustered configuration (default: false)
Expand Down Expand Up @@ -1491,6 +1493,9 @@ In general the configuration parameters are the same as the command line argumen
| hb_interval | Interval at which the server sends an heartbeat to a client | Duration | `hb_interval: "10s"` |
| hb_timeout | How long the server waits for a heartbeat response from the client before considering it a failed heartbeat | Duration | `hb_timeout: "10s"` |
| hb_fail_count | Count of failed heartbeats before server closes the client connection. The actual total wait is: (fail count + 1) * (hb interval + hb timeout) | Number | `hb_fail_count: 2` |
| nc_ping_interval | NATS Client ping interval in seconds. If not informed, NATS Streaming considers the NATS Client default value. | Number > 0 | `nc_ping_interval: 2` |
| nc_max_pings_out | NATS Client max pings out. If not informed, NATS Streaming considers the NATS Client default value. | Number > 0 | `nc_max_pings_out: 4` |

| ft_group | In Fault Tolerance mode, you can start a group of streaming servers with only one server being active while others are running in standby mode. This is the name of this FT group | String | `ft_group: "my_ft_group"` |
| partitioning | If set to true, a list of channels must be defined in store_limits/channels section. This section then serves two purposes, overriding limits for a given channel or adding it to the partition | `true` or `false` | `partitioning: true` |
| cluster | Cluster Configuration | Map: `cluster: { ... }` | **See details below** |
Expand Down
2 changes: 2 additions & 0 deletions nats-streaming-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Streaming Server Options:
-hbf, --hb_fail_count <int> Number of failed heartbeats before server closes the client connection
--ft_group <string> Name of the FT Group. A group can be 2 or more servers with a single active server and all sharing the same datastore.
-sl, --signal <signal>[=<pid>] Send signal to nats-streaming-server process (stop, quit, reopen)
-npi, --nc_ping_interval <uint> NATS Client ping interval in seconds. If not informed, NATS Streaming considers the NATS Client default value.
-npo, --nc_max_pings_out <int> NATS Client max pings out. If not informed, NATS Streaming considers the NATS Client default value.

Streaming Server Clustering Options:
--clustered <bool> Run the server in a clustered configuration (default: false)
Expand Down
12 changes: 12 additions & 0 deletions server/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ func ProcessConfigFile(configFile string, opts *Options) error {
return err
}
opts.SyslogName = v.(string)
case "npo", "nc_max_pings_out", "nats_client_max_pings_out":
if err := checkType(k, reflect.Int, v); err != nil {
return err
}
opts.NCMaxPingsOut = v.(int)
case "npi", "nc_ping_interval", "nats_client_ping_interval":
if err := checkType(k, reflect.Uint, v); err != nil {
return err
}
opts.NCPingInterval = v.(uint)
}
}
return nil
Expand Down Expand Up @@ -600,6 +610,8 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
fs.BoolVar(&sopts.SQLStoreOpts.NoCaching, "sql_no_caching", defSQLOpts.NoCaching, "Enable/Disable caching")
fs.IntVar(&sopts.SQLStoreOpts.MaxOpenConns, "sql_max_open_conns", defSQLOpts.MaxOpenConns, "Max opened connections to the database")
fs.StringVar(&sopts.SyslogName, "syslog_name", "", "Syslog Name")
fs.IntVar(&sopts.NCMaxPingsOut, "nc_max_pings_out", defaultNatsClientMaxPingsOut, "NATS Client max pings out before try to reconnect")
fs.UintVar(&sopts.NCPingInterval, "nc_ping_interval", defaultNatsClientPingInterval, "NATS Client ping interval in seconds")

// First, we need to call NATS's ConfigureOptions() with above flag set.
// It will be augmented with NATS specific flags and call fs.Parse(args) for us.
Expand Down
14 changes: 14 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ const (
// Interval at which server goes through list of subscriptions with
// pending sent/ack operations that needs to be replicated.
defaultLazyReplicationInterval = time.Second

defaultNatsClientMaxPingsOut = 0
defaultNatsClientPingInterval = 0
)

// Constant to indicate that sendMsgToSub() should check number of acks pending
Expand Down Expand Up @@ -1119,6 +1122,8 @@ type Options struct {
Partitioning bool // Specify if server only accepts messages/subscriptions on channels defined in StoreLimits.
SyslogName string // Optional name for the syslog (usueful on Windows when running several servers as a service)
Clustering ClusteringOptions
NCPingInterval uint //Optional config that change value Ping interval of nats client. This config is defined in seconds. Default value is 2 minutes.
NCMaxPingsOut int //Optional config that change value Max pings out of nats client. Default value is 2.
}

// Clone returns a deep copy of the Options object.
Expand Down Expand Up @@ -1281,6 +1286,15 @@ func (s *StanServer) createNatsClientConn(name string) (*nats.Conn, error) {
return nil, err
}
}

if s.opts.NCPingInterval > 0 {
ncOpts.PingInterval = time.Duration(s.opts.NCPingInterval) * time.Second
}

if s.opts.NCMaxPingsOut > 0 {
ncOpts.MaxPingsOut = s.opts.NCMaxPingsOut
}

// Shorten the time we wait to try to reconnect.
// Don't make it too often because it may exhaust the number of FDs.
ncOpts.ReconnectWait = 250 * time.Millisecond
Expand Down