Distributed System Lecture 3
Distributed System Lecture 3
Lecture 3 – Processes
Pan Hui
pan.hui@helsinki.fi
Huber Flores
huber.flores@helsinki.fi
Recap
• Different architecture styles
• Basic automaton
PROCESSES
Agenda
• Threads
• Virtualization
• Clients
• Servers
• Code migration
• Modelling
Introduction to threads
• Process ~ a program in execution in a virtual processor
created by the operating system
– Concurrency transparency of multiple processes enforced by OS
• Independent state information
• Independent address spaces
• Interact only via IPC (inter-process communication) mechanism
Expensive context switch (CPU, memory, address caches)
– A process typically comprises of multiple (parallel) threads
providing finer granularity of control
Thread implementation
• Two approaches for implementing thread package
Thread implementation
• Lightweight process (LWP) ~ hybrid form of user-level and kernel-
level threads
– LWP runs in context of single (heavy-weight) process
• There can be several LWPs per process
– User-level thread package is implemented entirely in user space
• Shared by multiple LWPs, each LWP can run its own user-level thread
Thread implementation
• LWP operation
– LWP is created with a system call and given its own stack
– LWP executes scheduling routine provide by the thread
package to search for a runnable thread from a shared
thread table
– Upon finding a runnable thread LWP switches context (in
user space) to that thread
– When a thread makes a blocking system call
• Execution changes from user mode to kernel mode, and continues in the context of
current LWP
• If current LWP cannot continue, OS switches context to another LWP (and back to user
mode)
– Mutually exclusive access control to shared resources (e.g.
thread table) with mutexes implemented in user space
Thread implementation
• Pros / cons of using LWPs with user-level thread package
+ Creating/destroying/synchronizing threads is relatively cheap
(no kernel involvement)
+ Blocking system call will not suspend entire process (assuming
process has enough LWPs)
+ LWPs are transparent to applications
+ Transparent multiprocessing by executing different LWPs on
different CPUs
- Creating/destroying LWPs is as expensive as with kernel-level
threads, though it needs to be done only occasionally
• Similar alternative: scheduler activations
– Upon a thread blocking on system call, kernel makes an upcall
to thread package, calling scheduler to select next runnable
thread, likewise when a thread is unblocked
– Saves management of LWPs by the kernel
– Violates the principle of layered design
Helsinki, Finland, 2018.
24
Virtualization
• Resource virtualization
– E.g. multithreading on a single CPU for creating an illusion of
parallelism (simultaneous execution)
• Role of virtualization in distributed systems
– Support porting of legacy interfaces to new platforms
– Reduce diversity of platforms and machines by letting each application
run on its own virtual machine
Clients
• Two approaches for networked user interfaces
– Application-specific protocol
• Handles synchronization with
remote service
Clients
• Example: The X Window system
– X kernel
• Contains all terminal-specific device drivers, HW dependent
• Offers relatively low-level interface (as a library called Xlib) for controlling screen and
capturing events from keyboard and mouse
– X protocol
• Application-level communication protocol for an instance of Xlib to exchange data and
events with X kernel
– Window manager
• Dictates the ”look and feel” of the display
– Concurrent
• Passes the request to a separate thread or another process, and waits
for next incoming request (e.g. multithreaded server),
or
• Forks a new process for each new incoming request
Server clusters
• General organization of three-tiered server cluster
– Switch (front end) provides a single access point to realize
access transparency (hides the internal organization of the
server cluster from clients)
Server clusters
• TCP handoff performed by transport layer switch
– Switch accepts incoming TCP connection requests
– Switch identifies the best server for handling the
request and forwards the request packet to that
server
– The server replies to the client, inserting the switch’s
IP address (IP spoofing) as the source IP address in the
reply
– Load balancing (round robin, content-aware request
distribution)
Server clusters
Code migration
• Goal: passing programs (sometimes even while they are
being executed), not just data
• Motivation
– Performance improvement
• Load distribution
• Parallel execution
– Flexibility via dynamic
configuration of clients
• Challenges
The principle of dynamically configuring a
– Security: can you trust
client to communicate with a server. The
the migrating code?
client first fetches the necessary software,
and then invokes the server.
Helsinki, Finland, 2018.
41
• Resource-to-machine bindings
– Unattached resource: can be easily moved between machines
• E.g. files associated only with the program being migrated
– Fastened resource: can be moved only with high cost
• E.g. local databases, complete web sites
– Fixed resource: cannot be moved
• E.g. local devices and local communication end points (ports)
Helsinki, Finland, 2018.
45
MODELLING
State
• A state is an abstraction of values an links of an
object
– A given object has a finite number of possible states
– It can only be in one state at a time
– At a given moment, various objects can exist each one
with its one state
Events
• An event is the specification of some
occurrence that may potentially trigger effects
by an object
• Kinds of events
– Call event
– Signal event
• Reliable channel
– Change event
– Time event
Call events
• A call event represents the reception of a
request to invoke a specific operation
– A call event is distinct from the call action that
caused it
Signal event
• A signal is an explicit one-way transmission of
information from one object to another
– Reliable channel
– A signal event is asynchronous
– A call event is a two-way synchronous
communication
Change events
• A change event is an event that is caused by
the satisfaction of a boolean expression
Time event
• A time event is an event that is caused by the
occurrence of an absolute time or the elapse
of a time interval
Hands-on session
• SVM (Python)
• Acronym of Statechart Virtual Machine
– Developed by Thomas Huining Feng
• A simulator Statecharts
– Standalone animation of statecharts
– SVM provides bindings for several programming
languages
• Web page
– http://msdl.cs.mcgill.ca/people/tfeng/uml/svm.html
Helsinki, Finland, 2018.
58
Hands-on session
• Statechart: Visual vs textual
Hands-on session
• Download the tools and demo
– http://huberflores.com/lectures/handsonsession-
lecture3.zip
Running SVM
• Configure the environment variables
(Windows)
– PATH=%PATH%;C:\Software\Python25;C:\Software\svm-0.3beta3-src
– set PYTHONPATH=.;C:\Software\svm-0.3beta3-src
Syntax summary
Exercise
• Play with the lighbulb example (provided)
Your tasks
• For next lecture session:
– Read Chapter 4 Communication (From Van Steen)
– Get acquiantance with the tools
– Extend the lighbulb example to support ‘flashing“
• Quiz in the practical session
• First task: Texas Watch
– Description in course web page
– Thursday 15, 2018, midnight
– Each hour late is 10% less points
• After 6 hours, value of the task is 50%
QUESTIONS