System Architecture:
Centralized architecture, Decentralized architecture, hybrid architecture
Logical organization of components in distributed systems:
– Component: A modular unit with well-defined interfaces that is replaceable
– Connector: a mechanism that mediates communication, coordination among
components.
we have layer-based and object based In (a), requests (resp. responses) go downward (resp. upward) In (b), objects communicate through Remote Procedure Calls (RPCs)
Event-based and data-centered (a) Event-based architecture: communication through events, thatoptionally carry data (subscribers get their desired events delivered) (b) Data-centered architecture: through a shared repository, that contains
data (e.g., files in a distributed file system)
有状态微服务与无状态微服务之间的主要区别在于,无状态微服务不在主机上存储数据,而有状态微服务则需要在为请求服务的主机上进行某种存储。 保持状态对于有状态服务至关重要。
layer-based
user layer, processing layer, data layer
Hosting different layers on different machines
– Three-tiered architecture:
– each layer on separate machine
– Two-tiered architecture:
– client
– single server configuration
– Single-tiered architecture:
– dumb terminal
– mainframe configuration
P2P
Every machine is both a client and a server
– No centralized control: the responsibility is distributed evenly
– Even the program executing on each machine is similar
– Forms an overlay network,
– nodes are processors,
– links possible communication channels
结构化对等模型
– Chord是分布式哈希表(DHT)的示例 pg22
使用确定性过程构建覆盖网络
http://archive.cone.informatik.uni-freiburg.de/teaching/lecture/peer-to-peer-w16/slides/p2p16-03.pdf
Edge-Server Systems
– Servers are placed at the edge of the network.
– Edge servers serve content, possibly after applying filtering
and transcoding functions
– One edge server acts as an origin server for all content, while
taking advantage of other servers for optimized delivery of
content, e.g. through replication.
边缘服务器是一种边缘设备,可提供进入网络的入口点。 其他边缘设备包括路由器和路由交换机。 边缘设备通常放置在Internet交换点(IxP)内,以允许不同的网络连接并共享传输。
Precessor:
-Previously: a distributed system gives the illusion of a single
system to a user thanks to transparency
– Now: a single system gives the illusion of multiple resources to
multiple users thanks to concurrency
Solution: scheduling program executions, one after the other during
small fractions of the time
Processes
Process: defined as a program in execution
– Operating system creates a virtual CPU for each process
– OS makes sure that processes cannot maliciously or
inadvertently affect each other’s behaviour, i.e. Secure !
– This concurrent transparency comes at a very high cost:
– For every process (virtual CPU), OS must create a completely
independent address space.
Address space
– Process address space:
– Stack: temporary data extensible towards lower virtual
addresses
– Heap: memory allocated dynamically extensible to higher
virtual addresses
– Data section: global variable
– Text region: program code
Switching from one process to another has become one of the
most expensive operations due to Context-Switches
– CPU context: register values, program counter, stack pointer, etc.
– Modify registers of MMU (Memory management unit)
– Invalidate address translation caches such as in TLB (Translation
lookaside buffer)
进程表示程序正在执行,而线程表示进程的一部分。
进程不是轻量级的,而线程是轻量级的。
一个进程花费更多的时间来终止,而该线程花费更少的时间来终止。
进程花费更多的时间来创建,而线程花费更少的时间来创建。
进程可能需要花费更多时间进行上下文切换,而线程需要更少的时间进行上下文切换。
一个进程大部分是孤立的,而线程共享内存。
进程不共享数据,并且线程彼此共享数据。
什么是线程?
线程是执行单元,它是进程的一部分。 一个进程可以有多个线程,所有线程都同时执行。 它是并发编程中的执行单元。 线程是轻量级的,可以由调度程序独立管理。 它可以帮助您使用并行性来提高应用程序性能。
多个线程共享信息,例如数据,代码,文件等。我们可以通过三种不同的方式实现线程:
内核级线程
用户级线程
混合线程
Processes
– Isolated: prevents one process from interfering with another
– Inefficient: starting/terminating a process and context switches
are costly
Threads
– Non-isolated: avoiding incorrect interferences makes
programming harder
– Efficient: a thread is a lightweight version of a process
– Multiple threads of control per process
https://www.tutorialspoint.com/operating_system/os_multi_threading.htm
multi thread 注意点:
An object state is its data, stored in state variables such as instances or static fields
– A shared variable is a variable that could be accessed by multiple threads
– A mutable variable is a variable whose value may change
– Whenever more than one thread access a given state variable and one of them might
write to it, they all must coordinate their access to it using synchronization
– If multiple threads access the same mutable state variable without appropriate
synchronization, the program is broken.
Conclude:
-Concurrency has been used for decades since hardware was
powerful enough to address multiple human needs
– Processes are heavy but protected whereas threads are
lightweight but non-protected
– Threads require synchronization to be protected from each
other
– Consumer/Producer and Dipatcher/Worker models makes it
easier to develop servers that exploit parallelism to attain high
performance