西维蜀黍

【macOS】iTerm2效率

快捷键

光标移动

  • 到行首:ctrl + A

  • 到行尾:ctrl + E

  • Option ⌥ + ← 和 Option ⌥ + → 来按 word 移动

  • 使用 Option ⌥ + ⌫ 来向左按 word 删除

  ...


【Linux】tmux

通过SSH远程连接到服务器,无法开启多个终端,只能再次ssh连接一次。那么问题来了,怎么通过ssh连接Linux,使用多个终端呢

  ...


【Linux】命令 - top

Meaning

  • PID: Shows task’s unique process id.

  • PR: Stands for priority of the task.

  • NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.

  • VIRT, RES, SHR and %MEM: These three fields are related with to memory consumption of the processes.

    • “VIRT”: Virtual Memory Size (KiB)
      • The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.
    • “RES” is the physical memory consumed by the process in RAM
    • “%MEM”: A task’s currently resident share of available physical memory.
    • SHR: Represents the Shared Memory size (kb) used by a task.
  • TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.

  • COMMAND: The COMMAND column shows the name of the processes.

  ...


【Kubernetes】管理 Container - crictl

List pods

List all pods:

$ crictl pods
POD ID              CREATED              STATE               NAME                         NAMESPACE           ATTEMPT
926f1b5a1d33a       About a minute ago   Ready               sh-84d7dcf559-4r2gq          default             0
4dccb216c4adb       About a minute ago   Ready               nginx-65899c769f-wv2gp       default             0
a86316e96fa89       17 hours ago         Ready               kube-proxy-gblk4             kube-system         0
919630b8f81f1       17 hours ago         Ready               nvidia-device-plugin-zgbbv   kube-system         0
  ...


【Docker】Docker - image 常用命令

Introduction

**Docker 把应用程序及其依赖,打包在 image 文件里面。**只有通过这个文件,才能生成 Docker 容器。image 文件可以看作是容器的模板。Docker 根据 image 文件生成容器的实例。同一个 image 文件,可以生成多个同时运行的容器实例。

# 查看当前本机有的镜像
$ docker image ls

# 将 image 文件从仓库抓取到本地
$ docker image pull [image_name]

# 删除镜像
$ docker rmi [image id]
# Or
$ docker image rm [image_name]

image 文件是通用的,一台机器的 image 文件拷贝到另一台机器,照样可以使用。一般来说,为了节省时间,我们应该尽量使用别人制作好的 image 文件,而不是自己制作。即使要定制,也应该基于别人的 image 文件进行加工,而不是从零开始制作。

为了方便共享,image 文件制作完成后,可以上传到网上的仓库。Docker 的官方仓库 Docker Hub 是最重要、最常用的 image 仓库。此外,出售自己制作的 image 文件也是可以的。

  ...


【Distributed System】分布式事务 - Saga

Context

You have applied the Database per Service pattern. Each service has its own database. Some business transactions, however, span multiple service so you need a mechanism to implement transactions that span services. For example, let’s imagine that you are building an e-commerce store where customers have a credit limit. The application must ensure that a new order will not exceed the customer’s credit limit. Since Orders and Customers are in different databases owned by different services the application cannot simply use a local ACID transaction.

  ...


【Distributed System】分布式事务 - TCC

Background

咱们先来看看业务场景,假设你现在有一个电商系统,里面有一个支付订单的场景。

那对一个订单支付之后,我们需要做下面的步骤:

  • 更改订单的状态为“已支付”
  • 扣减商品库存
  • 给会员增加积分
  • 创建销售出库单通知仓库发货

这是一系列比较真实的步骤,无论大家有没有做过电商系统,应该都能理解。

进一步思考

好,业务场景有了,现在我们要更进一步,实现一个 TCC 分布式事务的效果。

什么意思呢?也就是说

  1. 订单服务-修改订单状态
  2. 库存服务-扣减库存
  3. 积分服务-增加积分
  4. 仓储服务-创建销售出库单

上述这几个步骤,要么一起成功,要么一起失败,必须是一个整体性的事务。

假设现在订单的状态都修改为“已支付”了,结果库存此时库存已经是0,因此该订单下单失败。

结果呢?还是扣了用户的钱,这不是坑人吗?

  ...


【Distributed System】一致性模型(Consistency Model)

Consistency Model

In computer science, consistency models are used in distributed systems like distributed shared memory systems or distributed data stores (such as filesystems, databases, optimistic replication systems or web caching). The system is said to support a given model if operations on memory follow specific rules.

The data consistency model specifies a contract between programmer and system, wherein the system guarantees that if the programmer follows the rules, memory will be consistent and the results of reading, writing, or updating memory will be predictable. This is different from coherence, which occurs in systems that are cached or cache-less, and is consistency of data with respect to all processors. Coherence deals with maintaining a global order in which writes to a single location or single variable are seen by all processors. Consistency deals with the ordering of operations to multiple locations with respect to all processors.

  ...


【Database】ACID

Transactions

A transaction is a way for an application to group several reads and writes together into a logical unit. Conceptually, all the reads and writes in a transaction are executed as one operation: either the entire transaction succeeds (commit) or it fails (abort, rollback). If it fails, the application can safely retry. With transactions, error handling becomes much simpler for an application, because it doesn’t need to worry about partial failure—i.e., the case where some operations succeed and some fail (for whatever reason).

ACID

A transaction is a single logical unit of work which accesses and possibly modifies the contents of a database. Transactions access data using read and write operations.

In computer science, ACID (atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of databases, a sequence of database operations that satisfies the ACID properties (which can be perceived as a single logical operation on the data) is called a transaction.

For example, a transfer of funds from one bank account to another, even involving multiple changes such as debiting one account and crediting another, is a single transaction.

  ...


【Database】Cassandra

Cassandra

Cassandra is a free and open-source, distributed, wide-column store, NoSQL database management system designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. Cassandra offers support for clusters spanning multiple datacenters, with asynchronous masterless replication allowing low latency operations for all clients.

  ...