Managed Connections¶
This module provides the capability to from an abstract Paypal name, such as “paymentserv”, or “occ-conf” to an open connection.
The main entry point is the ConnectionManager.get_connection(). This function will promptly either:
1- raise an Exception which is a subclass of socket.error 2- return a socket
ConnectionManagers provide the following services:
1- name resolution (“paymentserv” to actual ip/port from topos) 2- transient markdown (keeping track of connection failures) 3- socket throttling (keeping track of total open sockets) 4- timeouts (connection and read timeouts from opscfg) 5- protecteds
In addition, by routing all connections through ConnectionManager, future refactorings/modifications will be easier. For example, fallbacks or IP multi-plexing.
-
class
support.connection_mgr.
Address
(ip, port)¶ -
ip
¶ Alias for field number 0
-
port
¶ Alias for field number 1
-
-
class
support.connection_mgr.
AddressGroup
(tiers)[source]¶ An address group represents the set of addresses known by a specific name to a client at runtime. That is, in a specific environment (stage, live, etc), an address group represents the set of <ip, port> pairs to try.
An address group consists of tiers. Each tier should be fully exhausted before moving on to the next; tiers are “fallbacks”. A tier consists of prioritized addresses. Within a tier, the addresses should be tried in a priority weighted random order.
The simplest way to use an address group is just to iterate over it, and try each address in the order returned.
tiers: [ [(weight, (ip, port)), (weight, (ip, port)) ... ] ... ]
-
class
support.connection_mgr.
AddressGroupMap
[source]¶ For dev mode, will lazily pull in additional addresses.
-
class
support.connection_mgr.
ConnectInfo
(connect_timeout_ms, response_timeout_ms, max_connect_retry, transient_markdown_enabled, markdown)¶ -
connect_timeout_ms
¶ Alias for field number 0
-
markdown
¶ Alias for field number 4
-
max_connect_retry
¶ Alias for field number 2
-
response_timeout_ms
¶ Alias for field number 1
-
transient_markdown_enabled
¶ Alias for field number 3
-
-
class
support.connection_mgr.
ConnectionManager
(address_groups=None, address_aliases=None, ssl_context=None)[source]¶ -
-
get_addr
(name)[source]¶ returns the first address which the logical name would resolve to, equivalent to get_all_addrs(name)[0]
-
get_all_addrs
(name)[source]¶ returns the all addresses which the logical name would resolve to, or raises NameNotFound if there is no known address for the given name
-
get_connection
(name_or_addr, ssl=False, sock_type=None, read_timeout=None)[source]¶ name_or_addr - the logical name to connect to, e.g. “db-r” ssl - if set to True, wrap socket with context.protected;
if set to an SSL context, wrap socket with that- sock_type - a type to wrap the socket in; the intention here is for protocols
that want to run asynchronous keep-alives, or higher level handshaking (strictly speaking, this is just a callable which accepts socket and
returns the thing that should be pooled, but for must uses it will probably be a class)
-
-
class
support.connection_mgr.
MonitoredSocket
(sock, registry, protected, name=None, type=None, state=None)[source]¶ A socket proxy which allows socket lifetime to be monitored.
-
class
support.connection_mgr.
ServerModel
(address)[source]¶ This class represents an estimate of the state of a given “server”. “Server” is defined here by whatever accepts the socket connections, which in practice may be an entire pool of server machines/VMS, each of which has multiple worker thread/procs.
For example, estimate how many connections are currently open (note: only an estimate, since the exact server-side state of the sockets is unknown)