ChaskiRemote: Proxy for Distributed Network Interactions

ChaskiRemote is designed to facilitate communication across distributed networks. It acts as an intermediary, managing interactions and ensuring robust connectivity.

Key Features:

  • Scalability: Easily manage multiple network nodes.

  • Reliability: Ensure consistent and reliable data transmission.

  • Flexibility: Adapt to various network topologies and protocols.

Server

The ChaskiRemote server facilitates network communication by acting as a proxy for distributed nodes. It ensures robust connectivity, reliable data transmission, and handles the management of various network protocols and topologies seamlessly.

[2]:
from chaski.remote import ChaskiRemote

server = ChaskiRemote(port='65432')
server.address
[2]:
'ChaskiRemote@127.0.0.1:65432'
None: Registered numpy
None-2024-07-20 17:47:26.174817: Calling numpy.random with args:None kwargs:None
None-2024-07-20 17:47:26.177237: Calling numpy.random.normal with args:None kwargs:None
None-2024-07-20 17:47:26.178215: Calling numpy.random.normal with args:(0, 1, (4, 4)) kwargs:{}

Client

The ChaskiRemote client leverages the server’s capabilities to facilitate remote interactions. By connecting to the proxy server, clients can seamlessly execute distributed commands and access shared resources across the network without dealing with the complexities of network communication protocols.

[3]:
client = ChaskiRemote()
await client.connect(server.address)

Connect to Remote NumPy

Once connected to the ChaskiRemote server, you can access and use the registered libraries, such as NumPy, as if they were local.

[4]:
np = client.proxy('numpy')
np
[4]:
ChaskiProxy(numpy, ChaskiRemote@127.0.0.1:55889)

Use remote Numpy

The following code generates a 4x4 matrix with normally distributed random numbers using the remote NumPy library connected through ChaskiRemote.

[5]:
np.random.normal(0, 1, (4, 4))
[5]:
array([[-1.93861735, -0.83464899, -0.97370041,  0.39538987],
       [ 0.45003648, -0.29468189,  0.67619071,  0.29004616],
       [ 0.87512625,  0.11887405, -0.19767929, -1.2296509 ],
       [-3.38679334, -0.45981944,  0.23840313, -0.79860475]])

Restrict Module Access

To limit the module access in ChaskiRemote, you can specify the modules that the server can provide to clients. This ensures that only the specified modules are accessible, enhancing security and control over the network interactions.

[6]:
server = ChaskiRemote(port='65433', available=['numpy'])
server.address
[6]:
'ChaskiRemote@127.0.0.1:65433'
None: Registered numpy

Here we initialize the ChaskiRemote client and set up a connection to the server. This connection allows the client to interact with remote resources and execute distributed commands seamlessly.

[7]:
client = ChaskiRemote()
await client.connect(server.address)

After connecting, we use the client.proxy method to access the numpy library remotely. This feature enables the use of remote libraries as if they were local, making distributed computing more accessible.

[8]:
client.proxy('numpy')
[8]:
ChaskiProxy(numpy, ChaskiRemote@127.0.0.1:56117)

Similarly, other libraries like scipy cannot be accessed using the client.proxy method because it is not in the list of available modules. This demonstrates the security and control provided by ChaskiRemote in limiting module access for network-based operations.

[9]:
client.proxy('scipy')
Module scipy not found in the conected edges

Attributes and Methods

Here we initialize a ChaskiRemote server specifying os as an available module. Then we set up a client to connect to this server, allowing remote access to the os module.

[11]:
server = ChaskiRemote(port='65434', available=['os'])
client = ChaskiRemote()

await asyncio.sleep(0.3)
await client.connect(server.address)
await asyncio.sleep(0.3)

remote_os = client.proxy('os')
remote_os
None: Registered os
[11]:
ChaskiProxy(os, ChaskiRemote@127.0.0.1:44043)
None-2024-07-20 17:47:50.213203: Calling os.name with args:None kwargs:None
None-2024-07-20 17:48:00.417942: Calling os.name with args:None kwargs:None
None-2024-07-20 17:48:02.301224: Calling os.name with args:None kwargs:None
None-2024-07-20 17:48:03.745586: Calling os.name with args:None kwargs:None

os.name should be a string

[12]:
remote_os.name
[12]:
'posix'

The type of remote_os.name is ObjectProxying

[13]:
type(remote_os.name)
[13]:
chaski.remote.ChaskiObjectProxying(str)

It is possible to access the correct value by calling remote_os.name._

[14]:
remote_os.name._
[14]:
'posix'

or using Context Managers, you can ensure that the remote attribute is correctly obtained and cleaned up, thus preventing potential resource leaks or unintended states in your distributed network interactions.

[15]:
with remote_os.name as name:
    name  # is a string