5102 - Foundations of Comp Sys
← 5102 - Foundations of Comp Sys
session: "5102-foundations-of-comp-sys/2026-10-24 0000 FCS 24 Oct"
title: "FCS 24 Oct"
date: "2026-10-24 00:00"
duration: "1h 48m"
language: "en"
model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"
parts: 3
transcript_chars: 62250
generated: "2026-11-23T16:02:35+05:30"
This session used a small Python proof-of-work blockchain (pow_blockchain.py) as a workload for observing how the operating system manages CPU execution, processes, memory and system calls — the blockchain itself was not the subject. The class covered blockchain definitions (blocks, hashes, immutability, consensus, advantages/disadvantages), walked through the Python code (argparse, hashlib/SHA-256, multiprocessing), and then ran the program live under top at several difficulty/worker/block settings. The observations (CPU ~99%, load average, process IDs changing per round, memory untouched) were used to motivate identifying CPU-, memory- and storage-intensive code, performance testing as a quality gate, and the developer's options (optimize, add cores, limit usage, vertical scaling, auto-scaling). It sits in the course where the ISA/machine-code contract meets the OS's management of processes and resources: the program is the workload, the OS is what we are watching.
python3 -u and interpret top output: CPU utilization, load average, memory/free/used/buffer cache/swap, process IDs, users.Definition: A peer-to-peer network holding a shared immutable ledger; immutable = cannot modify, permanently recorded = can only append (cannot modify, cannot remove). All data is grouped into blocks with capacity limits; a filled block is closed and a new block is attached to the previous one, forming a chain and a historical record of all transactions.
Why it matters: The append-only property is what the class later contrasts with normal mutable storage, and it is the source of the "immutability as a con" discussion.
Connection: The chain structure (each block carrying the previous block's hash) is exactly what the code implements and what the live runs exercise.
Definition: Each block contains a unique code called a hash; each block is identified by its hash and by the hash of the previous block. The previous-block hash is what links blocks.
Why it matters: The hash is the identity/reference of a block, not the shared content; the only way to retrieve data from a block is to identify it by its hash.
Connection: In the code, the hash function takes index, timestamp, data, previous hash and nonce — the hash field itself is not included because it is the output of the calculation.
Definition: Once a block is attached it is permanent — cannot be moved out of the chain or reordered. Analogy: stacking concrete blocks in a building — once placed/set, it is done forever; remove a block from the middle and the entire chain falls/breaks.
Why it matters: A new block can only be appended after the current last block (block N becomes block O); it cannot be inserted between existing blocks (e.g., between H and J, or C and D). By default no removal, no deletion, no modification.
Connection: The previous block provides its identity (hash) to the new block; no authentication is required from the previous block — it just says "I am connected to block N."
Definition: On a decentralized network, most computers on the network (nodes) must reach a consensus that the transaction/trade is real. Validation criteria, validation rules, acceptance criteria and acceptance rules are all established before the blockchain is created.
Why it matters: Consensus can be random from the nodes of the cluster — it need not be every node. Example: if the mechanism says any three nodes consenting means the entire network consents, that is built in; with 250 nodes in the cluster, the mechanism may require any three nodes to agree. There is no single way of consensus; each type has a different methodology, technology and way of work.
Connection: Named mechanisms: proof of work and proof of stake (details explicitly deferred — not covered in this session). Authentication is not done by blocks, it is done by nodes.
Definition: (1) The identity hash used for linking is distinct from (2) the public/private key hashes used for authentication/validation. The second hash can be generated using different technologies, even third-party tools.
Why it matters: Analogy: knowing the flat number (357) and phone number of a resident is not enough — you must provide identity at the security gate, and the person you are visiting must approve entry. The public key is input into the authentication system and mapped with the private key; the person who allows you is not the security but the person you came to meet. Authentication failing is not necessarily a bad thing (e.g., the person is not at home).
Connection: SHA-256's way of working is not changed; technologies are used as-is to arrive at the outcome, not modified.
Advantages: (1) Immutability — data cannot be erased or replaced; prevents data tampering and manipulation. (2) Transparency — the network is decentralized, allowing any member to scrutinize the recorded data (example: 2 million nodes all have access to all the blocks in the chain — transcript says "2,000 blocks", see Flagged). (3) Security — transactions require validation from network members; combined with immutability and transparency, a block added with data is protected from third-party attacks, and there is no room for rogue administration activities (if that happens the chain breaks and a new chain must be created with all the blocks).
Disadvantages: (1) High cost of implementation — reduces cost for users but requires high cost for companies; proper planning and implementation are a must. (2) Performance — carries out more operations and is slower than traditional databases; inefficiency arises from several network users validating a single transaction. Analogy: a single if condition checking whether a variable is more than 10 is fast, but one million such if conditions will definitely slow down. (3) Immutability as a con — example: a transaction for $10, later the parties compromise at $9 — you cannot change $10 to $9; rewriting is incredibly time-consuming and very expensive. Hence in industry it is implemented where not much modification of data is required.
Connection: These pros/cons motivate why the class treats blockchain as a workload and why the lecturer expects it to remain niche.
Types: Four, based on structure, characteristic and usage: public, private, hybrid, consortium (named only, not elaborated).
Applications: financial markets, healthcare, decentralized finance, real estate, smart contracts. Financial services: Bitcoin and Ethereum are popular cryptocurrencies built on blockchain. Healthcare: Medicalchain — described as one of the first medical companies to implement blockchain to help facilitate storage and utilization of electronic medical records; used for a safer and faster way of managing data and tracking medical supplies. Supply chain: IBM Food Trust — a project to help improve the food supply chain. Real estate: Propy — a platform using blockchain to transform how people market, search for, buy, sell and invest in real estate.
History: Concept first described by scientists Haber and Sternetta in 1991. A white paper published under the name Satoshi Nakamoto focusing on Bitcoin, a peer-to-peer electronic cash system, in 2018 (as spoken — see Flagged). The Bitcoin blockchain was made open source and released to the public in January 2009, making it possible to examine the code and reuse it.
Definition: A small blockchain implementation with these parts:
argparse (argument parsing), hashlib (cryptographic hashing, includes SHA-256; the proof-of-work algorithm depends on it), json (converts structured block data into a consistent serialized representation), multiprocessing as mp (creates and manages independent worker processes), plus os, time, and date/time.multiprocessing is what is responsible for creating the operating system processes when the Python program is executed.mine_worker: each worker receives the block information, target difficulty, its own ID, the total number of workers, and a shared result queue Q. target = "0" * difficulty. The nonce is initialized to the worker ID, so the initial nonce differs between workers. An attempt counter records how many hashes this worker has calculated; a timer measures its elapsed mining time. The worker runs a while loop that calculates the hash for the current nonce and increments the counter.if condition in the worker: tests whether the hash satisfies the proof-of-work requirement.mine_block: coordinates the mining workers and assembles the resulting block; generates the timestamp, creates a queue for worker results, initializes the list to track the processes, and contains a for loop (also somewhat CPU intensive, but unlike a while loop).validate_chain: validates which chain and at what difficulty level. If target is 0 that is the initialization target, but it gets modified depending on the difficulty level supplied as input at execution. Validation has multiple stages: validate the genesis block first, then validate the subsequent blocks; it goes through the entire chain ensuring all blocks attached to the chain have valid data, and protects it.if condition checking difficulty must be between 1 and 6, and workers must be at least 1 (cannot be 0).Why it matters: The lab parameters are (1) difficulty level, (2) block parameters, i.e. the hash, (3) the arguments. Framing: if we can identify which part of the program consumes more CPU and which requires more memory, it is easy for us to manage.
Connection: This is the workload whose behavior under top is the OS observation of the session.
pow_blockchain.py under topDefinition: Running the Python program and watching it with top in a second terminal. python3 -u — the -u option enables unbuffered standard output and standard error, helping progress messages appear promptly.
Why it matters: The runs show CPU-bound behavior (CPU up to 99%, memory untouched), sequential execution on a two-core machine, and process IDs changing between rounds (different processes/system calls created).
Connection: This is the concrete evidence behind the performance discussion and the testing-level discussion.
Definition: If the system sends 300 records per second (or 3,000 records), you are expected to create 300 blocks (or 3,000 blocks) per second. In the deliberately constructed case, one block took 66 seconds; another completed in 1.9 seconds; delays of 3 seconds, 10 seconds, and up to 30 seconds and 50 seconds were built in on purpose (higher difficulty and higher number of blocks cause some blocks to slow down).
Why it matters: An analyst watching the trend sees data delayed by seconds and misses the trend, making a wrong buy/sell decision — the decision-making system the design was meant for does not work.
Developer's options (as stated): optimize the code; increase the number of cores in the CPU; or limit the program's usage. If blocks could be processed in parallel, a speedier response to the customer would be achieved; currently it runs sequentially because resources are not available. This behavior should have been caught in unit testing / performance testing. Scale concern: one block addition takes milliseconds; what if 3,000 blocks must be added? Bombay Stock Exchange can send 3,000 transactions in a second — "pretty much possible."
Vertical scaling: in the cloud, when the program is known to be highly CPU sensitive, scale up CPU only for that moment so the customer is not impacted; a report later shows e.g. "we were using 12 cores of CPU, now we have increased it to 24", and you then address which part of the program consumes more cores.
Auto-scaling: the "second option" — blindly increase infrastructure if auto-scaling is available (cloud only). It indirectly increases cost of operations: the more resources used, the more the cloud provider bills.
Connection: This is the "why" behind identifying CPU/memory/storage-intensive code: if code accesses more data directly from storage it is storage-intensive and needs storage supporting that rate of access; if memory-intensive and not given appropriate memory it will hit the threshold and give alerts/issues. CPU and memory are the two critical ones; if these two can be managed, other things can be managed. This should be identified while writing code, or at least during performance testing.
Definition: Functional testing = level 0; performance testing = level 1; security testing = level 2. All three must be qualified for the code to go into production. Unit testing is done before the code reaches the quality team ("pre-unit 0, pre-testing level 0"); what the lecturer performed in this session is described as a unit test.
Why it matters: In performance testing the quality team asks whether utilization is appropriate, whether resources are planned appropriately, and whether the code must be optimized or resources added. These calls are taken from this type of testing.
Connection: The live top runs are exactly this kind of evidence gathering.
Definition: There is no fixed minimum number of nodes required; response goes down depending on the degree of decentralization you want for security — the more nodes, the more secure. With three or four nodes it is centralized, so it is not really blockchain at that level.
Why it matters: As of now the code is a single server — only one node.
Connection: Distribution has two senses: (1) servers in different regions (e.g., AWS US and Australia) are part of the cluster maintaining the blockchain; (2) a block stored on one server may be followed by a block on another server in the same or a different data center — data is not stored sequentially on one server. The hash (created from the nonce) links blocks; each block has the previous hash so the system/network knows where the previous block is. Data is distributed — not like a single MySQL server holding all data. Blocks can be split between servers, and whichever server stores a particular block of data is the owner of that data; it still must go ahead with the consensus before the data gets added.
target = "0" * difficulty — target is the hex prefix the hash must match; difficulty is the number of leading zeros required. Used to construct the proof-of-work target in mine_worker.1 is the pre-existing genesis block; the second term is the number of blocks mined in the run. Used to predict the chain length after a run (mining 3 blocks gives 4 blocks in chain; mining 6 gives 7).difficulty is the count of leading zeros (difficulty 4 → 4 zeros; difficulty 6 → 6 zeros). Used to interpret the difficulty argument.1 is the threshold on the load-average scale as the lecturer uses it; the reading is compared against it. Used when reading top's load average.worker ID is the per-worker identifier passed to mine_worker; the initial nonce differs between workers. Used so workers start from different nonces.if condition checking a variable > 10 is fast; one million such if conditions (i.e., one million members each having to agree) will definitely slow down.
One line per segment, [hh:mm:ss] timestamp first.
loading…