Links & Libraries

Virtual Memory The first thing we need to have a clear idea of what we normally call memory is that what we are talking about is actually virtual memory, not manipulation of real physical memory. On a bare metal machine without an operating system installed, the memory we are dealing with is physical memory. As computers evolved, a program called an “operating system” was installed on the computer, which took over all the hardware resources and provided us with a layer of abstraction.

Several ways to run services in the background on Linux

There are several common ways to run programs in the background of Linux. ctrl+z screen nohup supervisor systemd The following practice is based on the Ubuntu2204 system, but theoretically other Linux distributions are also applicable. 1. Distinguish usage scenarios If the command takes a little longer to execute and you don’t need to see the output, use & as a background run flag or use ctrl+z to hang the process in the background after running, combined with jobs and fg to switch the background tasks of the current session.

GMP Model for Go Scheduler

Go implements a goroutine scheduler in its own runtime for the efficiency of its goroutine execution and scheduling. The following is a simple code to show the goroutine of a Go application at runtime for better understanding. The Go scheduler is part of the Go runtime, and the Go runtime is built into your application 1 2 3 4 5 6 for i := 0; i < 4; i++ { go func() { time.

Automatic update of running Docker containers

Nowadays, everyone is definitely containerizing their services, and how to effectively manage and upgrade the containers without affecting the existing services is an important issue. However, in the CI/CD flow, there are definitely two steps that are necessary, the first is to package the environment into a Docker Image and upload it to the company’s private Docker Registry, after uploading, connect to the machine via SSH and pull the new image file, and then restart the running service through the Graceful Shutdown mechanism.

Usage of Python __slots__

Python is a dynamic language, and you can add or subtract properties or methods to instances or classes dynamically. But using the __slots__ attribute can qualify class or instance properties and methods; without __slots__ the instance properties and methods are contained in the instance’s __dict__ dictionary, and the class properties and methods are contained in the class’s __dict__ dictionary. The following problems may occur when using __slots__ as written in the normal way.

The xargs command in linux

xargs stands for build and execute, a somewhat odd name (many commands in linux are abbreviated, and all seem odd to me). Another explanation might be easier to remember: execute with arguments. Use the tldr tool to see the basic usage of xargs. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $ tldr xargs xargs Execute a command with piped arguments coming from another command, a file, etc.

Python Virtual Environment Creation and Management

Why do I need to create a virtual environment? Virtual environments are created to use different versions of the Python interpreter, third-party libraries, and dependencies required by different Python projects on the same computer to avoid version conflicts and issues that affect each other. A virtual environment is a separate Python runtime environment in which you can install and manage project-specific dependencies that do not affect other projects. This means you can develop multiple Python projects in parallel on the same computer with different dependencies and versions without worrying about conflicts between them.

The find command in linux

find Usage. 1 2 3 $ find --help Usage: find [-H] [-L] [-P] [-Olevel] [-D debugopts] [path...] [expression] ... Indicates that a file (folder) is found under a path. Entering a single find will display all files and folders in the current directory. 1 2 3 4 5 6 7 8 $ find . ./app ./app/file1.txt ./app/file2.txt ./file1.txt ./file2.txt ./file3.txt Search in the specified directory Look in the . /app/ directory to find files.

Getting Started with Golang in 10 Minutes

The purpose of this article is to give you a quick introduction to the Go language, so that you can spend about ten minutes reading through the whole article and have a preliminary knowledge of Go, and lay the foundation for further in-depth learning of Go. This article assumes that you have no contact with Go at all. You may be a programmer who is proficient in other programming languages, or you may be a person who has no programming experience and just wants to become a programmer.

C++ move Semantic Basics

The role of move semantics Look directly at an example. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <iostream> struct S { S() { std::cout << "S()\n"; } S(const S&) { std::cout << "S(const S&)\n"; } ~S() { std::cout << "~S()\n"; } }; S foo() { return S(); } int main() { foo(); } Compile with the following command. 1 clang++ -std=c++03 -fno-elide-constructors The results are as follows.

Unit testing with vitest

Introduction vitest is a new unit testing tool that is fast, supports esm by default, is compatible with the jest api, and can be considered a better jest. by default, it supports the following features being used very fast esm support ts support Compatible with jest api support for vite support for multiple frameworks react/vue Installation vitest internally depends on vite, but it is not necessary to install vite. 1 npm i -D vitest Configuration Well, actually vitest is really zero configuration and supports ts/esm/tsx, but if you want more features, you can indeed create vitest.

A bizarre Pulsar InterruptedException

Background Today, I received feedback from the business team that an online application failed to send a message to Pulsar, and after checking the logs, I learned that a java.lang.InterruptedException exception was thrown when sending the message. After communicating with the business, we learned that the message sending was triggered in a gRPC interface, and the exception lasted about half an hour before returning to normal, which is the background of the whole problem.

Prometheus and Grafana Installation and Deployment

Overview I’m familiar with the Prometheus model, so usually some server software and small applications are monitored through Prometheus. Although I often build Prometheus environments, I don’t summarize them, so I need to go to various places to find the configuration (systemd, prometheus, nginx configuration, etc.) every time. Recently, I just had a new environment and needed to rebuild it, so I took the opportunity to document the process of installing and configuring prometheus and grafana.

Python Craftsman: Statements, Expressions, and Walrus Operators

Let’s start with two lines of the simplest Python code. 1 2 3 >>> name = 'piglei' >>> print(f'Hello {name}!') Hello piglei! It’s a “Hello World” program, and you’ve probably seen it a million times and know every letter of it by heart. But what you probably never realized is that the two lines of code above correspond to two important concepts in Python: statement and expression. Specifically, name = 'piglei' is an assignment line that assigns the string 'piglei' to the name variable.

How to determine if Golang interface variables are equal

Recently a reader asked me a question with the following code. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 func main() { printNonEmptyInterface1() } type T struct { name string } func (t T) Error() string { return "bad error" } func printNonEmptyInterface1() { var err1 error // Non-null interface type var err1ptr error // Non-null interface type var err2 error // Non-null interface type var err2ptr error // Non-null interface type err1 = T{"eden"} err1ptr = &T{"eden"} err2 = T{"eden"} err2ptr = &T{"eden"} println("err1:", err1) println("err2:", err2) println("err1 = err2:", err1 == err2) // true println("err1ptr:", err1ptr) println("err2ptr:", err2ptr) println("err1ptr = err2ptr:", err1ptr == err2ptr) // false } His question is: “How is it understood that when dynamic types are pointers, interface variables are not equal, and when dynamic types are not pointers, interface variables are equal?

C++ Smart Pointer Guide

std::unique_ptr unique_ptr It is a pointer to exclusive resource ownership. unique_ptr is allocated on the stack and then freed after leaving the scope, deleting the Resource object held inside. As of C++ 11, we can use unique_ptr like this. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <iostream> #include <memory> // for std::unique_ptr class Resource { public: Resource() { std::cout << "Resource acquired\n"; } ~Resource() { std::cout << "Resource destroyed\n"; } }; int main() { // allocate a Resource object and have it owned by std::unique_ptr std::unique_ptr<Resource> res{ new Resource() }; return 0; } // res goes out of scope here, and the allocated Resource is destroyed New in C++14 is the make_unique function, which allows us to construct a unique_ptr object (supporting array objects).

JavaScript Date and Time Formatting

1. Date and time formatting 1.1. Native methods 1.1.1 Using the toLocaleString method The Date object has a toLocaleString method that formats the datetime according to the local time and locale settings. For example. 1 2 3 const date = new Date(); console.log(date.toLocaleString('en-US', { timeZone: 'America/New_York' })); // 2/16/2023, 8:25:05 AM console.log(date.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })); // 2023/2/16 上午8:25:05 The toLocaleString method

Pipeline in Shell

The content of this article requires the reader to know some of the syntax and role of the shell, the purpose of the shell, and some basic usage. To learn shell scripting, it is important to understand the concept of pipeline and the concept of input and output of command. Only by mastering pipeline can we write better shell scripts, and this chapter introduces pipeline in detail. The command in the shell can accept some input and then produce some output, similar to the function expression y = f(x) in mathematics, input the parameter x and get the result y, the command can be regarded as a functional equation.

Which is more efficient, distinct or group by in MySQL?

Conclusion Let’s start with the general conclusion (full conclusion at the end of the article) With the same semantics and indexes: group by and distinct can both use indexes with the same efficiency. With the same semantics and no indexes: distinct is more efficient than group by. The reason is that both distinct and group by perform grouping operations, but group by may sort and trigger filesort, resulting in inefficient sql execution.

Illustrating the Evolution of Kubernetes & OpenShift Container Networks

Compared to traditional virtualization, Kubernetes containers have shorter lifecycles, higher volume densities, and faster cluster change rates. The container network then must take full account of the high-speed communication between cluster nodes. In addition, the secure isolation of resources between compute loads carrying many tenants on an enterprise-class container cloud platform must also be taken into account. Obviously, the traditional physical network architecture can not meet the needs of high flexibility of containers, container networks must have a new design architecture, Kubernetes rapid development and evolution, where the development of this aspect of the network changes the fastest, the most prosperous ecology.