西维蜀黍

【macOS】网络管理

Install

Alternative ip

$ brew install iproute2mac
$ ip link show
$ ip -s link 

Interfaces

List Devices with the Interface Number

$ networksetup -listnetworkserviceorder
(1) Ethernet
(Hardware Port: Ethernet, Device: en0)

(2) USB 10/100/1000 LAN
(Hardware Port: USB 10/100/1000 LAN, Device: en5)

(3) Wi-Fi
(Hardware Port: Wi-Fi, Device: en2)

(4) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en3)

Route

View The Routing Table

$ netstat -nr
Routing tables

Internet:

Destination     Gateway        Flags      Refs     Use     Netif Expire
default         10.1.1.1       UGSc       36       65      jnc0
default         192.168.0.1    UGScI      20       0       en1
  ...


【Docker】Container 常用命令 - network

网络端口映射

Docker网络端口映射使得通过访问宿主机器上的某个端口,可以访问到某个Docker容器上的端口。这样Docker容器就可以对外提供服务了。

查看某个容器的端口映射情况

$ docker port [containerId]

https://docs.docker.com/engine/reference/commandline/run/

  ...


【Distributed System】Partitioning

Partitioning

Replication—that is, having multiple copies of the same data on different nodes. For very large datasets, or very high query throughput, that is not sufficient: we need to break the data up into partitions, also known as sharding.

Normally, partitions are defined in such a way that each piece of data (each record, row, or document) belongs to exactly one partition. There are various ways of achieving this. In effect, each partition is a small database of its own, although the database may support operations that touch multiple partitions at the same time.

The main reason for wanting to partition data is scalability. Different partitions can be placed on different nodes in a shared-nothing cluster. Thus, a large dataset can be distributed across many disks, and the query load can be distributed across many processors.

  ...


【Engineering】Fault Tolerance

Fault Tolerance

Fault tolerance is the property that enables a system to continue operating properly in the event of the failure of one or more faults within some of its components. If its operating quality decreases at all, the decrease is proportional to the severity of the failure, as compared to a naively designed system, in which even a small failure can cause total breakdown. Fault tolerance is particularly sought after in high-availability, mission-critical, or even life-critical systems. The ability of maintaining functionality when portions of a system break down is referred to as graceful degradation.

A fault-tolerant design enables a system to continue its intended operation, possibly at a reduced level, rather than failing completely, when some part of the system fails. The term is most commonly used to describe computer systems designed to continue more or less fully operational with, perhaps, a reduction in throughput or an increase in response time in the event of some partial failure. That is, the system as a whole is not stopped due to problems either in the hardware or the software. An example in another field is a motor vehicle designed so it will continue to be drivable if one of the tires is punctured, or a structure that is able to retain its integrity in the presence of damage due to causes such as fatigue, corrosion, manufacturing flaws, or impact.

Within the scope of an individual system, fault tolerance can be achieved by anticipating exceptional conditions and building the system to cope with them, and, in general, aiming for self-stabilization so that the system converges towards an error-free state. However, if the consequences of a system failure are catastrophic, or the cost of making it sufficiently reliable is very high, a better solution may be to use some form of duplication. In any case, if the consequence of a system failure is so catastrophic, the system must be able to use reversion to fall back to a safe mode. This is similar to roll-back recovery but can be a human action if humans are present in the loop.

  ...


【Distributed System】Replication

Why Replication

Replication means keeping a copy of the same data on multiple machines that are connected via a network. There are several reasons why you might want to replicate data:

  1. To keep data geographically close to your users (and thus reduce latency)
  2. To allow the system to continue working even if some of its parts have failed (and thus increase availability)
  3. To scale out the number of machines that can serve read queries (and thus increase read throughput)

What is Replication

Replication in computing can refer to:

Replication in space or in time is often linked to scheduling algorithms.

  ...


【Distributed System】Replication - Leader-based Replication

Leader-based Replication (Active/passive or Master–slave Replication)

Each node that stores a copy of the database is called a replica.

Every write to the database needs to be processed by every replica; otherwise, the replicas would no longer contain the same data. The most common solution for this is called leader-based replication (also known as active/passive or master–slave replication)

  1. One of the replicas is designated the leader (also known as master or primary). When clients want to write to the database, they must send their requests to the leader, which first writes the new data to its local storage.
  2. The other replicas are known as followers (read replicas, slaves, secondaries, or hot standbys). Whenever the leader writes new data to its local storage, it also sends the data change to all of its followers as part of a replication log or change stream. Each follower takes the log from the leader and updates its local copy of the database accordingly, by applying all writes in the same order as they were processed on the leader.
  3. When a client wants to read from the database, it can query either the leader or any of the followers. However, writes are only accepted on the leader (the followers are read-only from the client’s point of view).
  ...


【Distributed System】Data Flow

Dataflow Through Databases

  ...


【MySQL】常用 SQL 语句(Common SQL)- Display

显示DBs and Tables

mysql> show databases;
+----------------------------------+
| Database                         |
+----------------------------------+
| entry_task2_db                   |
| information_schema               |
| mysql                            |
| performance_schema               |
| sw_benchmark_test                |
| sw_benchmark_test_oltp_read_only |
| sw_test                          |
| sys                              |
+----------------------------------+

mysql> use sw_test;

mysql> SHOW TABLES;
+--------------------------------------------------+
| Tables_in_sw_test                                |
+--------------------------------------------------+
| logistic_promotion_seller_promo_budget_tab       |
| logistic_promotion_seller_promo_budget_usage_tab |
| logistic_promotion_seller_promo_channel_map_tab  |
| logistic_promotion_seller_promo_rule_map_tab     |
| logistic_promotion_seller_promo_tab              |
| seller_grouped_rule_budget_tab_00000004          |
| seller_grouped_rule_budget_usage_tab_00000005    |
| tb_person                                        |
| user                                             |
+--------------------------------------------------+
9 rows in set (0.00 sec)
  ...


【Engineering】How to Write Code

  ...


【Engineering】Logging

Log Levels

The log level is used to denote the severity of each event in the system. In most logging frameworks, the following levels are available.

  • FATAL: denotes very severe error events that will presumably lead the application to abort. Usually, these can end up in catastrophic failures.
  • ERROR: denotes error events that might still allow the application to continue running, with reduced capabilities in the affected paths.
  • WARN: denotes less-harmful events than errors. Usually, they do not lead to any degradation of capabilities or complete failure of the application. However, they are still red flags and must be investigated.
  • INFO: denotes the important event banners and informational messages in the application behaviour.
  • DEBUG: denotes specific and detailed information, mainly used for debugging purposes. These logs help us step through the code.
  • TRACE: denotes most low-level information like stack traces of code to provide the most information on a certain event/context. These logs help us inspect the variable values and full error stacks.
  ...