jina.peapods.networking module

class jina.peapods.networking.ConnectionList(port)[source]

Bases: object

Maintains a list of connections and uses round roubin for selecting a connection

Parameters

port (int) – port to use for the connections

add_connection(address, connection)[source]

Add connection with ip to the connection list :type address: str :param address: Target address of this connection :param connection: The connection to add

remove_connection(address)[source]

Remove connection with ip from the connection list :type address: str :param address: Remove connection for this address :returns: The removed connection or None if there was not any for the given ip

get_next_connection()[source]

Returns a connection from the list. Strategy is round robin :returns: A connection from the pool

pop_connection()[source]

Removes and returns a connection from the list. Strategy is round robin :returns: The connection removed from the pool

has_connection(address)[source]

Checks if a connection for ip exists in the list :type address: str :param address: The address to check :rtype: bool :returns: True if a connection for the ip exists in the list

class jina.peapods.networking.ConnectionPool(logger=None, on_demand_connection=True)[source]

Bases: object

Manages a list of connections.

Parameters
  • logger (Optional[JinaLogger]) – the logger to use

  • on_demand_connection – Flag to indicate if connections should be created on demand

send_message(msg, target_address)[source]

Send msg to target_address via one of the pooled connections

Parameters
  • msg (Message) – message to send

  • target_address (str) – address to send to, should include the port like 1.1.1.1:53

Returns

result of the actual send method

start()[source]

Starts the connection pool

close()[source]

Closes the connection pool

class jina.peapods.networking.GrpcConnectionPool(logger=None, on_demand_connection=True)[source]

Bases: jina.peapods.networking.ConnectionPool

GrpcConnectionPool which uses gRPC as the communication mechanism

class jina.peapods.networking.K8sGrpcConnectionPool(namespace, client, logger=None)[source]

Bases: jina.peapods.networking.GrpcConnectionPool

Manages grpc connections to replicas in a K8s deployment.

Parameters
  • namespace (str) – K8s namespace to operate in

  • client (kubernetes.client.CoreV1Api) – K8s client

  • logger (JinaLogger) – the logger to use

start()[source]

Subscribe to the K8s API and watch for changes in Pods

run()[source]

Subscribes on MODIFIED events from list_namespaced_pod AK8s PI

close()[source]

Closes the connection pool

send_message(msg, target_address)[source]

Send msg to target_address via one of the pooled connections.

Parameters
  • msg (Message) – message to send

  • target_address (str) – address to send to, should include the port like 1.1.1.1:53

Returns

result of the actual send method

jina.peapods.networking.is_remote_local_connection(first, second)[source]

Decides, whether first is remote host and second is localhost

Parameters
  • first (str) – the ip or host name of the first runtime

  • second (str) – the ip or host name of the second runtime

Returns

True, if first is remote and second is local

jina.peapods.networking.get_connect_host(bind_host, bind_expose_public, connect_args)[source]

Compute the host address for connect_args

Parameters
  • bind_host (str) – the ip for binding

  • bind_expose_public (bool) – True, if bind socket should be exposed publicly

  • connect_args (Namespace) – configuration for the host ip connection

Return type

str

Returns

host ip

jina.peapods.networking.create_connection_pool(args)[source]

Creates the appropriate connection pool based on args :type args: Namespace :param args: Arguments for this pod :rtype: ConnectionPool :return: A connection pool object