Neven Miculinic
A distributed system is one in which the failure of a computer you didn't even know existed can render your own computer unusable
- Leslie Lamport
A distributed system is a collection of autonomous computing elements that appears to its users as a single coherent system.
A brief introduction to distributed systems:
https://link.springer.com/article/10.1007/s00607-016-0508-7
nc -lu localhost 2345
nc -u localhost 2345
Each package is a number
// Error handling omitted
conn, _ := net.ListenPacket("udp", ":0")
defer conn.Close()
dst, _ := net.ResolveUDPAddr("udp", addr)
for i := 0; ; i++ {
conn.WriteTo([]byte(strconv.Itoa(i)+"\n"), dst)
time.Sleep(*writeInterval)
}
conn, _ := net.ListenUDP("udp", addr)
defer conn.Close()
numbers := make(chan int64)
go readNumberdFromUDP(conn, numbers)
t := time.NewTicker(*summaryInterval)
func readNumberdFromUDP(
conn *net.UDPConn,
numbers chan<- int64,
) {
buf := make([]byte, 1024)
for {
n, _, _ := conn.ReadFromUDP(buf)
x := ... // parse it
numbers <- x
}
}
for {
select {
case <-t.C:
// Write summary of msgs recieved
case x := <-numbers:
// Add number x to the summaries
}
}
recv: go run *.go recv
send: go run *.go send
goreman start
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
config.vm.network "private_network", type: "dhcp"
config.vm.define "host1"
config.vm.define "host2"
end
vagrant up
vagrant ssh host1
vagrant ssh host2
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
config.vm.network "private_network", type: "dhcp"
# Provisioning
config.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
ansible.compatibility_mode = "2.0"
end
config.vm.define "host1"
config.vm.define "host2"
end
playbook.yml
---
- hosts: all
become: yes
tasks:
- name: Install list of packages
apt:
name: "{{ packages }}"
state: present
update_cache: yes
vars:
packages:
- curl
- iproute2
- python3
- netcat
- python3-pip
playbook.yml
- pip:
name: pip
state: latest
executable: pip3
- pip:
name: tcconfig
state: latest
executable: pip3
- copy:
src: "dist-example"
dest: "/usr/bin/dist-example"
mode: 0755
A tc command wrapper. Easy to set up traffic control of network bandwidth/latency/packet-loss/packet-corruption/etc. to a network-interface/Docker-container(veth).
https://tcconfig.readthedocs.io
NetEm is an enhancement of the Linux traffic control facilities that allow to add delay, packet loss, duplication and more other characteristics to packets outgoing from a selected network interface. NetEm is built using the existing Quality Of Service (QOS) and Differentiated Services (diffserv) facilities in the Linux kernel.
tcset eth0 --rate 100Kbps \
--delay 500ms \
--loss 10 \
--reordering 20
tcshow eth0
tcdel eth0
ansible -i
(...) .vagrant/provisioners/ansible/
(...)inventory/vagrant_ansible_inventory
(...) all -b -a "ip a"
ansible trick
https://slides.com/nmiculinic/distributed-systems
https://github.com/nmiculinic/distributed-systems-01