Ably accounts are priced based on the total number of messages, peak channels and peak connections within any calendar month. Find out more about account limits and check our pricing page to find out how much it costs to upgrade your package to support more connections.
The peak connection figure is the maximum number of realtime clients simultaneously connected to Ably at any point in time within the month. For example, if you have 10,000 customers, and at your busiest time of the month there is a single spike with 500 customers with a realtime connection open to Ably, you will only be charged for 500 peak connections. The total number of clients or devices that connect to Ably throughout the month does not affect your bill.
Note that HTTP requests and connections used by REST clients do not count towards your peak connections.
In your account or app dashboard, the graph at the bottom of the page shows the minimum, maximum (peak) and average number of connections for the time period. See an example below:
Further technical details on how connections are counted in real time
Each Ably frontend server that accepts connections from clients counts the number of transports that are connected for a given app. The most common transport is WebSockets, however in order to support older browsers or very restrictive network environments, additional HTTP transports such as XHR and JSONP are supported. The total number of connected transports per app and account counts up each time a transport is connected, and down each time one is dropped.
These counts are updated when they change in a hash of connections maintained for each datacenter, and the counts and are then rolled up globally once every second i.e. viewing your live connection counts will be inaccurate by at least one second.
If a frontend server is abruptly terminated and thus all transports are closed, the corresponding member of the datacenter maintained hash is deleted ensuring we never miscount as a result of an abruptly terminated instance being unable to decrement the central count.
The usage stats for an account or app viewable in your dashboard (which includes message counts, peak channels etc) is aggregated every few seconds and persisted to disk in at least 2 regions.
Whenever account aggregates are calculated and persisted to disk, the connections, channels, messages and data used for that month are checked against the account package limits, and an appropriate action is taken if a limit is exceeded i.e. a notification may be sent to Ably staff instructing them to contact the customer, or, in severe cases, new connections or messages will be rejected on that account. Find out more about what happens if you exceed your account package limits.
Abrupt disconnections and page reloads
It is important to note that an abruptly disconnected client counts as one connection until the connection state is disposed of. For example, if you are connected to Ably, and your connection is abruptly disconnected because your app is terminated, then Ably will hold onto the connection state so that the connection can be recovered within two minutes (find out more about connection state recovery). If your app then establishes a new connection and does not recover the state, then until the old connection is disposed of (within two minutes of the abrupt disconnection), your connection count for your account will report two connections.
There are various ways to resolve this if you wish to prevent double counting for a period of up to two minutes:
- Explicitly close your connections, see Connection.close.
- If using other environments, you will have to manage the Ably connection yourself to suit your needs. For example, if using ably-js with React Native, if you don't want it to stay active when the app is backgroundend, then you can close() the Ably connection in the 'background' React Native AppState event handler, and re-open it (call connect()) in the 'active' handler.