metalbear-co / mirrord

Connect your local process and your cloud environment, and run local code in cloud conditions.
https://mirrord.dev
MIT License
3.81k stars 104 forks source link

Make the connection to the internal proxy lazy #1758

Open t4lz opened 1 year ago

t4lz commented 1 year ago

Currently when a new process is executed, the layer creates a connection to the internal proxy, which creates a new connection to the agent, which creates new resources (threads?) for the new client. When running a shell (e.g. zsh) with mirrord, execve can be called more then a 1000 times, which results in a 1000 layers, each of them creates a connection to the proxy, and the proxy creates a connection to the agent for each layer. Most of those processes are quickly replaced by the next process via execve, without having triggered any hook, and without actually needing any communication with the agent.

By making the connection to the internal proxy "lazy" (only connect the internal proxy on the first message to the agent) we could save all those resources both locally and on the agent.

See https://github.com/metalbear-co/mirrord/issues/1716#issuecomment-1663736500 for the kind of problem this could solve.

Razz4780 commented 1 year ago

Currently the internal proxy maintains only one connection to the agent. Nevertheless, when a new layer starts, it initializes internal data structures and makes a tcp connection to the internal proxy. Does the problem still exist?

t4lz commented 1 year ago

The specific issue mentioned above was solved already before, but this issue is about the possible optimisation of avoiding the creation of a TCP connection thousands of times unnecessarily. Now that there is only one connection to the agent the overhead is reduced, but if we wanted we could still eliminate all the unused layer->proxy TCP connections.