Question 2 of 11 · PYQ 2025 · 6 marks
Open in ChatGPTExplain the concept of code migration in distributed systems and discuss its benefits and challenges.
Introduction
Code migration is the movement of a program: its code, and optionally its execution state: from one node to another while the system runs. It is what makes a distributed system able to move work to where the data or the capacity is.
Types of migration
- Weak migration: only the code moves. The process restarts on the new node with a fresh state, re-reading its inputs.
- Strong migration: code and execution state (stack, registers, program counter, open resources) move, so execution resumes exactly where it stopped.
It is also classified by who initiates it:
- Sender-initiated: the current host pushes the process away, typically to shed load.
- Receiver-initiated: an idle host pulls work towards it.
- Self-initiated: the process decides to move, as a mobile agent does.
How it is done
- The code is transferred (or is already installed on the target).
- The execution state is captured: stack, registers, heap, and references to resources.
- Local resources are released or forwarded: file descriptors, sockets, locks.
- The state is restored on the target and execution continues.
The hard part is step 3: an open socket or a lock cannot be copied, so it must be re-established or explicitly transferred.
Benefits
- Load balancing: move work off an overloaded node without restarting the client.
- Data locality: move the computation to the data instead of the data to the computation.
- Fault avoidance: migrate away from a node that is about to fail or be maintained.
- Mobile agents: the computation follows a user or gathers data across sites and returns.
Challenges
- Portability: the target must have a compatible runtime and library set; a process linked to one architecture cannot simply be resumed on another.
- State capture: registers, thread stacks and kernel resources are not portable across operating systems.
- Resource rebinding: sockets, file handles and locks must be released and re-acquired, which can break a transaction.
- Security: accepting migrated code means executing someone else's program, so the target needs sandboxing and authentication.
- Consistency: moving a process that holds a cached copy or a lock leaves the old state behind.
Example
A cloud scheduler migrates a virtual machine from a host that is about to fail: the VM's memory and device state are copied to another host and resumed, and the guest never notices. Moving an ordinary process with an open TCP connection across hosts is not possible without breaking the connection, which is why strong migration in practice is done at the VM or container boundary.
Conclusion
Code migration lets a system place computation where it is cheapest, but only at the granularity its state can tolerate: whole VMs for strong migration, stateless workers for weak migration.