Linux Blocking IO

IO tasks An IO task is a process in which a program reads data from a file or writes data to a file, a process that generally requires the CPU to control it. For example, a network IO task. 1 2 3 4 5 6 7 8 9 10 11 12 //创建socket int s = socket(AF_INET, SOCK_STREAM, 0); //绑

Save files in batch in the browser

Recently, I received a business requirement that I need a batch export image function. It was suggested that the download task should be submitted to the server side, which would complete the packaging and then give the download link. I personally feel that this function can be implemented directly in the browser. So I did some research and found a feasible solution. Today, I will share it with you. The solution presented in this article uses Chrome’s proprietary API, so it will not work properly with Firefox 😂.

Using the Go language as a script - gomacro

gomacro is a near-complete Go interpreter, implemented in pure Go, that provides both interactive REPL and scripting modes and does not require the Go toolchain at runtime (except for some very specific scenarios: importing third-party packages at runtime). It has two dependencies outside the Go standard library: github.com/peterh/liner and golang.org/x/tools/go/packages. REPL is an acronym for Read-Eval-Print Loop, a simple, interactive programming environment where REPL means, respectively. Read: gets user input Eval: Evaluate the input Print: prints and outputs the result of the evaluation Loop: loop that repeats Read-Eval-Print over and over again REPL is very useful for learning a new programming language, and you can quickly verify your understanding through the output in this interactive environment.

How to properly retry requests in Go

One of the problems we can’t avoid in development is how to achieve reliable network communication in unreliable network services, and http request retry is a technique often used. However, the Go standard library net/http actually does not have retry function, so this article mainly explains how to implement request retry in Go. Overview In general, the handling of network communication failure is divided into the following steps. perceive the

Go 1.18 introduces three new packages: constraints, slices and maps

Let’s take a look at the three new Packages introduced in go1.18: constraints, slices and maps. Currently, these three packages are unified in golang.org/x/exp. The code can be found here. New any and comparable Go1.18 adds two syntax types, any and comparable, where any can be compared to the original interface, and developers can replace the original interface writing according to the context. Let’s take a look at the following example.

Use pyroscope adhoc to quickly find performance bottlenecks

When we develop software, we will iterate the project schedule and requirements rapidly. The fastest way to solve this problem is to scale vertically, adding CPU and memory first, but this is not a cure. This article will introduce a set of tools called pyroscope, which allows developers to quickly find the code of performance bottlenecks. Pyroscope currently supports many languages, such as Go, Python, Java, Ruby, Rust, PHP, and .

Recommend automated monitoring of website operation services - Gatus

After deploying a service, it’s important to make it clear to the team that the service is running. For example, GitHub provides a overall running page that monitors the status of common operations such as Git Operations, Webhooks, or GitHub Actions and other services. This allows developers to check the status of their services in real time when they encounter problems and take appropriate action. There are many online services like this, such as Atlassian’s Statuspage or PingPong, and more free services can be found directly at See awesome-status-pages for more free services.

Implementing Pub-Sub Mode with Go Languages

I believe you all know Publish / Subscribe mode, developers can use third-party open source tools like Redis, NSQ or Nats to implement the subscription mechanism, this article will teach you how to use Go Language to write a stand-alone version of Pub/Sub mode, which is very lightweight in a single system and does not need to rely on third-party services It is easy to implement. The following will directly use a single subscription Topic mechanism to write Publisher and Subscriber.

How Go reads data from Channel

The Go language’s powerful goroutine feature makes developers love it, and how do multiple goroutines communicate? It is through Channel to do so. This article teaches you two ways to read data from Channel and the timing of using it, and uses a case to quickly understand what problems will be encountered in Channel practice. The following two examples will help you understand how to read data from Channel.

Configuring timed tasks with systemd timer

1. Prepare the timing script If it is a Bash script, the first line needs to specify the interpreter. 1 2 3 4 5 6 7 8 9 10 11 12 #!/bin/sh /usr/local/bin/kubectl get pods --all-namespaces -o wide | grep Evicted | awk '{print $1,$2}' | xargs -L1 /usr/local/bin/kubectl delete pod -n /usr/local/bin/kubectl get pods --all-namespaces -o wide | grep Error | awk '{print $1,$2}' | xargs -L1 /usr/local/bin/kubectl delete pod -n /usr/local/bin/kubectl get pods --all-namespaces -o wide | grep Completed | awk '{print $1,$2}' | xargs -L1 /usr/local/bin/kubectl delete pod -n /usr/local/bin/kubectl get pipelinerun --all-namespaces -o wide | grep Succeeded | awk '{print $1,$2}' | xargs -L1 /usr/local/bin/kubectl delete pipelinerun -n /usr/local/bin/kubectl get pipelinerun --all-namespaces -o wide | grep PipelineRunTimeout | awk '{print $1,$2}' | xargs -L1 /usr/local/bin/kubectl delete pipelinerun -n /usr/local/bin/kubectl get pipelinerun --all-namespaces -o wide | grep InvalidWorkspaceBindings | awk '{print $1,$2}' | xargs -L1 /usr/local/bin/kubectl delete pipelinerun -n /usr/local/bin/kubectl get pipelinerun --all-namespaces -o wide | grep Failed | awk '{print $1,$2}' | xargs -L1 /usr/local/bin/kubectl delete pipelinerun -n /usr/local/bin/kubectl describe -A pvc | grep -E "^Name:.

Cracking ReCAPTCHA by simulated clicks

Previously, I shared the cracking scheme of ReCAPTCHA, which is to get one of the siteKey of ReCAPTCHA, and then submit the siteKey directly to the cracking service related to ReCAPTCHA to achieve cracking. This time, we will introduce a more flexible and powerful full simulated click cracking scheme, the overall idea is to identify all the CAPTCHA images and simulate a click on the ReCAPTCHA CAPTCHA based on the identification result, so as to finally pass the CAPTCHA.

Detailed profiling of the container runtime

Although the container field of entrepreneurship with the sale of CoreOS, Docker, and gradually relegated to silence, but with the rise of the Rust language, Firecracker, youki project in the container field ripples, for cloud-native practitioners, interviews and other scenarios will more or less talk about the history and technical background of some containers. Requirement Profile In the days of Docker, the term container runtime was well defined as the software that ran and managed containers.

New idea for Go error handling? Using left-hand functions and expressions

Error handling has been a very controversial area of Go, and people have contributed all sorts of ideas to proposals in that category. Recently, I also found an interesting technical proposal: the left-hand side function; and a new idea for Go+. Go’s new proposal: the left-hand side function With the existing Go1 error handling mechanism, we generally need to write a lot of if err ! = nil logic. Some people laughingly claim that 50 out of 100 lines of code are the following.

Kubernetes list/watch design and rationale

The design of kubernetes is broadly divided into 3 parts. API-driven features. Control loops and conditional triggers (Level Trigger). API extensibility. These design features are what make kubernetes work very stably. Level Trigger and Edge trigger I saw an online source that explains the two belongings as follows. condition-trigger(level-trigger) LT means: Triggers an event whenever the condition is met (constant notification as long as there is data not fetched). edge-trigger(edge-trigger)ET:

Golang Divide and conque practice (merge sort and fast sort)

1. Problem Divide and conquer algorithm means to split a complex problem into several similar subproblems until each subproblem can be solved simply and directly. Divide and conquer algorithms are the basis of many efficient algorithms, such as subsumption sorting, quick sorting, dichotomous search methods, etc., all use the idea of Divide and conquer algorithms The recursive algorithm is one of the most important ideas of Divide and conquer. 2.

K3s Tools Advanced Guide

K3s is a lightweight Kubernetes distribution that is highly optimized for edge computing, IoT, and other scenarios. Kubernetes distribution certified by CNCF. Support for X86_64 , ARM64 , ARMv7 platforms. A single process containing Kubernetes master , kubelet and containerd. 1. Introduction to K3s tools K3s has the following enhancements. Package as a single binary. Package K8S related components such as kube-api / kube-manager into a single binary, so that

Building Virtual Machine Images with Packer

This article shares a scenario on how to build a VM image on a VMware vSphere environment using Packer, and how to Run a k3s cluster and then run redfish-esxi-os-installer through the argo-workflow workflow engine muzi502/redfish-esxi-os-installer) to automate the installation of ESXi OS on the bare metal server. Prerequisites Download the ISO image of Base OS in advance, for example CentOS-7-x86_64-Minimal-2009.iso. A vCenter Server and a VMware ESXi are required

OpenEBS Usage Guide

What is OpenEBS? OpenEBS is an open source cloud native storage solution hosted at the CNCF Foundation, which is currently in the sandbox phase of the project. OpenEBS is a set of storage engines that allow you to choose the right storage solution for stateful workloads (StatefulSet) and Kubernetes platform types. At a high level, OpenEBS supports two main types of volumes - local and replicated volumes. OpenEBS is a

Benchmark Comparative Analysis Tool

In Go, it is easy to write Benchmark functions to test the performance of a function point. For important functions, we can add the corresponding test process in CI/CD to be aware of the function performance changes when they occur. So the question is, how do you detect performance changes in a function? To put it another way, you write a function and find that it is slow and you need to optimize it, and when you Google it and find a better implementation, you find that it is indeed faster through the Benchmark function.

Tracking rpcx microservices with ebpf

ebpf is an innovative and revolutionary technology that enables sandboxed programs to be run in the kernel without modifying the kernel source code or loading kernel modules. By making the Linux kernel programmable, it is possible to build smarter, more feature-rich infrastructure software based on existing (rather than adding new) abstraction layers, without increasing system complexity or sacrificing execution efficiency or security. The first version of BPF was introduced in