西维蜀黍

【Linux】命令 - journalctl

Boot Messages

# Show all messages from this [b]oot:
$ journalctl -b

# Show all messages from last [b]oot:
$ journalctl -b -1

# Show all messages from previous_boot's_offset [b]oot:
# e.g., the previous boot has an offset of -1, the boot before that is -2, and so on
$ journalctl -b -<offset>

# To list the boots of the system, use the following command.
$ journalctl --list-boots
-2 12792aa4791f4087a27f93a2bf4e191f Sun 2021-07-04 23:34:07 +08—Sun 2021-07-04 23:34:29 +08
-1 8e10828970ac4e7ebec55f268f6e945d Mon 2021-07-05 07:36:05 +08—Sun 2021-07-04 23:37:17 +08
 0 f027aa1e23c44e2c88d8203fc7f93575 Mon 2021-07-05 07:37:28 +08—Wed 2021-07-14 22:12:20 +08
  ...


【Docker】Contaienr OOM Debug

Problem

It’s one of the most common question that I come across: “Why is my container not running?”

Can docker container exit codes help troubleshoot this issue?

The first step in answering this question is to identify the exit code for the docker container. The exit code may give a hint as to what happened to stop the container running.

  ...


【Golang】benchmark

The Golang testing package contains a benchmarking facility that can be used to examine the performance of your Golang code. In this article we’ll see how to write simple benchmark tests that are able to provide us good insights about a given algorithmic solution.

  ...


【Linux】OS 如何保持当前时间

Time Stamp Counter

The Time Stamp Counter (TSC) is a 64-bit register present on all x86 processors since the Pentium. It counts the number of CPU cycles since its reset. The instruction RDTSC returns the TSC in EDX:EAX. In x86-64 mode, RDTSC also clears the upper 32 bits of RAX and RDX. Its opcode is 0F 31. Pentium competitors such as the Cyrix 6x86 did not always have a TSC and may consider RDTSC an illegal instruction. Cyrix included a Time Stamp Counter in their MII.

  ...


【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.

  ...