CS 544 — MASTER: Decks 2–5

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/102

flashcard set

Earn XP

Description and Tags

All 103 official Anki cards: Networking (39), Memory (17), Compute (26), Storage (21). Includes labeled corrections to two Compute Python API examples. Source: https://tyler.caraza-harter.com/cs544/f26/anki.html

103 Terms

1
New cards

How many bits are in a MAC address?

48

2
New cards

What does the prefix of a MAC address indicate?

The vendor/manufacter that produced the NIC

This is so that we can achieve globally unique MAC addresses (each vendor gets a prefix, and is expected not to reuse the same suffix for different devices).

3
New cards

How can you see the MAC addresses and IP addresses for your NICs?

ip address

4
New cards

What is a virtual NIC that is only reachable from the local machine, and what IP address does it use?

The "loopback" device, which has address 127.0.0.1

5
New cards

What is a network?

A collection of computers that can send each other messages by MAC address

6
New cards

Within a network, what device can forward data that is sent to a specific MAC address?

A switch

7
New cards

What is the device that connects multiple networks to form an internet, or the Internet?

a router

8
New cards

How many bits does an IPv4 address contain, and how many possible addresses are there?

32 bits, and about 4 billion possible addresses

9
New cards

What does the prefix of an IP address tell you?

It identifies the network

10
New cards

Why do routers forward based on IP address rather than MAC address?

Because there are too many MAC addresses in the world, and forwarding tables would need to be too big if every router needed to remember where every MAC address lives. With IP addresses, IPs with the same prefix are on the same network. A router just needs to know where to forward data to get it closer to the correct network.

11
New cards

The following are private IP ranges, meaning multiple networks can use the same IPs from these ranges internally: 192.168.0.0 to 192.168.255.255 172.16.0.0 to 172.31.255.255 10.0.0.0 to 10.255.255.255 What device/software can let us connect to machines using these IPs, given they are not unique?

A NAT (network address translation). It can map a unique public address to one or more private IPs within a network.

12
New cards

What is something that both UDP and TCP add in addition to what IP provides?

The both provide port numbers, which let us direct communication to a specific process on a machine

13
New cards

What is something that TCP provides that UDP does not?

TCP provides more reliable communication: retry when a packet is dropped buffer packets on receiving side and re-arrange so they arrive in the same order they were sent

14
New cards

What does UDP stand for?

User Datagram Protocol

15
New cards

What does TCP stand for?

Transmission Control Protocol

16
New cards

Why would you ever prefer UDP over TCP?

TCP does extra work, which is sometimes not necessary. For example, in a Zoom call, if some packets are dropped the session may freeze. After that, it's more natural for humans to repeat what they were saying (it would be weird if it replayed video/audio from the few seconds when the connection was lost).

17
New cards

What is the relationship between domain names in a URL and IP addresses? Example: https://tyler.caraza-harter.com:443/cs544/s23/schedule.html

When you enter a domain name into a browser, it gets translated to an IP address automatically for you.

18
New cards

If you are using HTTP over TCP/IP, what functionality does TCP/IP provide, and what does HTTP provide?

TCP/IP gives you IP addresses and port numbers, letting you communicate with a specific process (a server on a specific machine. HTTP additionally lets you specify what resource you want to access via that server. For example, consider this URL: https://tyler.caraza-harter.com:443/cs544/s23/schedule.html The resource is "/cs544/s23/schedule.html"

19
New cards

What does RPC stand for?

Remote Procedure Call Procedure: another name for a function/method Remote: we want it to run on a different process/container/computer

20
New cards

What are the RPC implementations created by Meta and Google called, respectively?

Thrift and gRPC

21
New cards

What is gRPC layered on top of?

HTTP Every method call is an HTTP POST request. The arguments go in the request body, the return value goes in the response body.

22
New cards

What is it called when we convert various data types into bytes to send over the wire? What about the reverse conversion?

serialization/deserialization

23
New cards

What does gRPC use for serialization?

Protocol Buffers (protobufs for short)

24
New cards

What is variable-length encoding, and what are the pros/cons of using it?

Use more space for bigger numbers. E.g., if an int32 value is small enough, we could use 1, 2, or 3 bytes (instead of the usual 4). Pros: save space. Very important for sending data over the network, so protobufs do this. Cons: CPUs cannot directly operate on int32's unless they are 4 bytes, so conversion is necessary before sending and after receiving this data.

25
New cards

Port forwarding: if we want to forward port 300 of the loopback device on a VM to port 80 inside a container, how do we run the container?

docker run -p 127.0.0.1:300:80 myimg

26
New cards

What does this do? ssh USER@VM -L localhost:1234:localhost:5678

This is executed on a machine (say your laptop) to create an SSH tunnel to the VM. While the tunnel is in use, any requests to localhost:1234 on the laptop will be forwarded to localhost:5678 on the VM ("localhost" is not redundant here because it is referring to two different loopback devices, the one on the laptop and the one on the VM).

27
New cards

Consider this: docker run -d -p 300:80 myimg We specify the port on the VM (300) and container (80), but we don't specify which NIC. What will be used?

By default, the command is equivalent to this: docker run -d -p 0.0.0.0:300:80 myimg This means traffic on all of the VM's NICs will forward to the container (possibly a security risk, depending on your firewall settings). Inside the container, it will forward to whatever the main NIC is (e.g., eth0), NOT the loopback device (so anything inside the container should listen on 0.0.0.0, not localhost).

28
New cards

What is container orchestration, and what is currently a very popular orchestrator?

Orchestration lets you deploy cooperating containers across many different machines. Kubernetes is probably the most well known.

29
New cards

What does "docker compose" do?

Lets you start a bunch of cooperating containers on the same machine.

30
New cards

protobuf files (.proto) can support two different syntaxes, v2 and v3. If you want v3, what should the first line of your .proto be?

syntax = "proto3";

31
New cards

What are the two main things a .proto file contains?

messages services Example: message MyMessage { … } service MyService { … }

32
New cards

In a .proto file, what does a message contain?

Fields, each with a type and a number, like this: message MyMessage { int32 x = 1; int32 y = 2; }

33
New cards

In a .proto file, what does a service contain?

RPCs, like this: service MyService { rpc MyRPC(Message1) returns (Message2); } Each RPC has one message containing arguments and another containing return values.

34
New cards

When you generate code for a .proto file, you get two files:

????_pb2

????_pb2_grpc


What are they each for?

????_pb2: code for serializing/deserializing the messages

????_pb2_grpc: servicer (class to be inherited from) and stubs for making remote procedure calls

35
New cards

Consider this: python3 -u server.py &> log.txt What does "-u" do?

"force the stdout and stderr streams to be unbuffered" Otherwise, if its buffered, any prints from server.py might not immediately appear in log.txt (that can be confusing if you're using log.txt to debug).

36
New cards

If you have a docker-compose.yml in the current directory, and you want to start running the services defined, what can you do?

docker compose up

37
New cards

If you want to see the compose containers currently running, what do you do?

docker compose ps

38
New cards

If you want to stop running containers for a compose cluster, what can you do?

docker compose down

39
New cards

If you want to delete all containers for a docker compose cluster, what can you do?

docker compose rm (add -f to force it; for example, might be necessary if they're currently running)

40
New cards

Before a CPU can add two values in RAM, what must it do?

Load those values to CPU registers

41
New cards

Which CPU cache level is fastest, of L1, L2, L3?

L1

42
New cards

Which CPU cache level is biggest, of L1, L2, L3?

L3

43
New cards

When data in a cache is too old and no longer valid, we say it is _______

stale

44
New cards

What does FIFO stand for?

First In First Out

45
New cards

What does LRU stand for?

Least Recently Used

46
New cards

How are FIFO and LRU similar? How are they different?

They are the same for a miss: the data is added to the cache, in the "newest" position. They are different for a hit: FIFO does not change how it prioritizes the item, but LRU resets it to the "newest" position.

47
New cards

What do you call it when you find an item in a cache?

"hit"

48
New cards

What do you call it when you CANNOT find an item in a cache?

"miss"

49
New cards

What is a pattern where a random eviction policy would beat LRU and FIFO?

A common pattern is that the data is too big to fit completely in cache, and the program loops, repeatedly reading over the dataset in the same order. LRU and FIFO will have a 0% hit rate, but random will at least get some hits.

50
New cards

What is the name for a piece of data loaded to CPU cache?

cache line

51
New cards

What is the most common cache line size for modern CPUs?

64 bytes is common (other sizes like 128 used to be more common; new Macs haved started using 128 again)

52
New cards

If you want to sum over column in a numpy matrix in a cache friendly way, how should you create the array?

First create an array where each column is actually stored as a row in the matrix. Then transpose it. This will get you columns that are contiguous in memory, resulting in fewer cache lines being loaded as the data is scanned.

53
New cards

How does PyArrow indicate which strings/ints/etc are null/None in an array?

validity bitmap: 1 means valid, 0 means null/None

54
New cards

How can you add a region to your virtual address space that is not backed by a file?

anonymous mmap

55
New cards

How can you map a file into your virtual address space?

Open the file, get the f.fileno(), and pass it to mmap.

56
New cards

If you want to be able to evict pages in anonymously mmap'd regions, what do you need to do?

enable a swap file in Linux

57
New cards

There is one virtual address space per _______

process

58
New cards

A process is a running ______

program

59
New cards

Virtual memory maps to ______

physical memory

60
New cards

Which address space can contain "holes" (invalid addresses)

Virtual address spaces can have holes (physical address spaces do not -- they are contiguous)

61
New cards

What are three things that go in a virtual address space?

code stack heap

62
New cards

Which pointer indicates what code to execute next?

The "instruction pointer"

63
New cards

There is one stack per _____ and one heap per ______

thread, process

64
New cards

What is it called when the scheduler stops running one thread and starts running a different one?

A "context switch"

65
New cards

What are three states a thread can be in?

running, blocked, ready

66
New cards

What are some reasons a thread might be blocked?

waiting on user input, disk operations, network operations, timer sleep, etc.

67
New cards

How do you create and launch a thread object for running function f(x)?

t = threading.Thread(target=f, args=(x,)); t.start() [Corrected Python API: target and args belong in Thread(), not start().]

68
New cards

How do you wait for a thread t to finish running?

t.join()

69
New cards

How can you print a thread's ID?

For the calling thread: threading.get_native_id(). For a started Thread object t: t.native_id. [Corrected Python API.]

70
New cards

What is a "race condition"

A bug that only sometimes surfaces, depending on when context switches happened between threads

71
New cards

When might a context switch occur?

Between instructions -- a single line of code might correspond to multiple bytecodes or machine instructions, so it's important to note that context switches often occur in the middle of a line of code being executed.

72
New cards

What is a "race condition"?

A bug, where whether or not you get correct behavior depends on how threads get scheduled. Race conditions are tricky to test+debug because they're non-deterministic (not same behavior each time), and you might only see the incorrect behavior rarely (say one in a million times).

73
New cards

What is "deadlock"?

This is when threads can never make progress, because they each want to acquire a lock that will never be released. One example: t1 has A and t2 and B; t1 is waiting to additionally acquire B, and t2 is waiting to additionally acquire A. This will never happen because neither thread will release its first lock until it has acquired the second lock and done some work.

74
New cards

How can a thread (a) get a lock and (b) let go of it?

lock.acquire() lock.release()

75
New cards

How can you rewrite the following code so that the release will happen, even if an exception occurs? lock.acquire() # code with possible exception lock.release()

with lock: # code with possible exception

76
New cards

What do you call a section of code where certain interleavings with other code would be a problem?

critical section

77
New cards

What is "atomicity" in the context of multi-threaded programs?

If a thread is changing multiple things together, we never want to see (say from another thread) partial results, with only some changes made.

78
New cards

What is an "invariant"?

A rule that applies to the data, often something a human might know from context. For example, an invariant might be a list of ages cannot contain negative numbers. Some invariants are known by the system (for example, that the length of the list itself cannot be negative).

79
New cards

What is "consistency" in the context of threading?

All invariants are enforced.

80
New cards

If thread t1 holds a lock, what could happen? 1. we could context switch to another thread t2 2. another thread t2 could acquire the lock

(1) is possible, (2) is not

81
New cards

What happens in Python when you try to release a lock that has already been released?

There is an exception

82
New cards

What is the GIL?

Global Interpreter Lock

83
New cards

Memory is byte-addressible. But what is the unit of access for an HDD, SSD, etc?

These are block devices, so the unit is a block . A typical block size might be about 512 bytes.

84
New cards

What are two ways we can use memory to make access to block devices more efficient?

caching: keep some disk data in memory, so we don't need to go back to disk if the data is reused buffering: when doing many smaller reads/writes, accumulate more data in memory before doing the transfer between disk and memory (because block devices are more efficient for bigger accesses).

85
New cards

What are the names for these two data access patterns? 1. reading lots of data in order 2. jumping around and reading from many different places

  1. sequential 2. random
86
New cards

"block" and "page" have different meanings for SSD internals than we've seen for operating systems and interactions with block devices. What are the differences?

block (for SSDs): unit of erasure (perhaps 100s of KBs)

block (for using a block device): unit of transfer to/from device, perhaps 512 bytes


page (for SSDs): unit of read/write within the define (few KBs)

page (for system memory): unit of mapping between virtual memory and physical memory (usually 4 KB)

87
New cards

How can we break a block device into smaller sections?

with partitions

88
New cards

How can we treat multiple individual block devices like one bigger, more reliabel one?

With RAID (redundant array of inexpensive disks)

89
New cards

What is the data structure in a file system that points to blocks containing file data?

inode

90
New cards

On UNIX, how do we make many smaller file systems appear as one big one?

By mounting them on top of each other

91
New cards

What does it mean for a format to be "column oriented"?

The data in the column is layout out consecutively in memory or within a file.

92
New cards

What is the orientation of CSVs and parquet files?

CSVs: row oriented Parquet: column oriented

93
New cards

What is the tradeoff between text encoded and binary encoded formats?

text: easier to debug (because you can just look at it) binary: usually more efficient (often less space, and numbers usually already in a format on which CPUs can directly operate without further conversion)

94
New cards

Compression works by looking for repetition over some window, say 32 KB. What would be the advantage and disadvage of increasing the window size?

Advantage: find more repetition, and use that to get a smaller file size Disadvantage: spend more computation time finding the repetition

95
New cards

What does snappy prioritize, high speed, or high compression ratios?

high speed from the docs: "[Snappy] does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression."

96
New cards

Considering CSVs and parquets: when do we need to infer the schema?

With CSVs we need to infer it, because everything in a CSV is a string (need to detect that all the strings in a given column look like integers, for example). Parquets have schema information built in, so there is no need to infer the schema.

97
New cards

What is transactions processing?

Operating on individual rows or a small number of rows at a time (e.g., adding, modifying, deleting rows).

98
New cards

What is analytics processing?

Trying to answer questions about the data, which involves computation over whole columns of data.

99
New cards

What does OLTP stand for?

Online Transactions Processing

100
New cards

What does OLAP stand for?

Online Analytics Processing