golang from kernel to epoll

Basic implementation of linux networking In the TCP/IP network hierarchy model, the entire protocol stack is divided into physical layer, link layer, network layer, transport layer, and application layer. The physical layer corresponds to the grid card and the grid line, and the application layer corresponds to various applications such as Nginx, FTP, etc. Linux implements the link layer, the grid layer, and the transport layer. In the Linux kernel

Shopee ClickHouse Cold and hot data separation storage architecture and practice

Shopee ClickHouse is a highly available distributed analytical database based on the open source database ClickHouse for secondary development and architectural evolution. This article will focus on Shopee ClickHouse’s hot and cold storage architecture and the practices that support the company’s business. Shopee ClickHouse’s hot and cold storage architecture uses JuiceFS clients to mount remote object storage to the local machine path, and uses remote object storage as if it were multi-volume storage by writing ClickHouse storage policies.

CSS content's new replacement element specification behavior explained

Can a normal element become a replacement element By replacement elements, we usually mean elements such as images, videos, etc., corresponding to HTML tags <img> and <video>, while elements such as <div>, <p>, <span>, etc., which are normally used for layout, are non-replacement elements. In fact, from 2019 onwards, the above rule has become inaccurate, or a rule that only holds under constraints. In other words, elements such as <div>,

Talk about some tips for using Unsafe

I remember when I first learned Java, just after learning the syntax basics, I came across reflection, a feature provided by Java, although it seems to be a very basic knowledge point now, but at that time, I was undoubtedly excited, and I instantly felt that I was out of the “Java beginner” team. As I gained experience, I gradually learned a lot of similar points that I was excited about, and the Unsafe technique was definitely one of them.

Illustrating Kubernetes Ingress

Kubernetes Ingress is just a common resource object in Kubernetes that requires a corresponding Ingress Controller to resolve Ingress rules and expose the service to the outside, such as ingress-nginx, which is essentially just an Nginx Pod that then redirects requests to This Pod itself is also exposed through the Kubernetes service, most commonly through LoadBalancer. Again, this article wants to give you a simple and clear overview of what’s behind Kubernetes Ingress to make it easier for you to understand the Ingress in use.

Write a do-it-yourself Kubernetes YAML templating tool

When we write resource manifest files with Kubernetes, we often use tools like Helm or Kustomize for templating, both to improve the flexibility of resource manifests and to really lower the threshold for installing complex Kubernetes applications. In this article we try to implement a YAML resource manifest file templating solution ourselves using Golang. Golang’s Templating Golang has a standard library text/template that supports templated text files. This library allows

Understanding Linux network namespaces

In this article I will demonstrate how to use the command to connect processes in different subnets of the network namespace through a pair of veth interfaces. Network Namespaces We know that the container runtime uses the namespace (namespace) kernel function to partition system resources for some form of process isolation, so that changes to resources in one namespace do not affect resources in other namespaces, including process IDs, host

Adding DNS records to Pods

We all know that Pods in a StatefulSet have separate DNS records. For example, if a StatefulSet is named etcd and its associated Headless SVC is named etcd-headless, CoreDNS will resolve an A record for each of its Pods as follows. etcd-0.etcd-headless.default.svc.cluster.local etcd-1.etcd-headless.default.svc.cluster.local …… So can other Pods besides the one managed by StatefulSet also generate DNS records? As shown below, we only have a Headless SVC here, not a Pod managed by StatefulSet, but a Pod managed by ReplicaSet, and we can see that it seems to generate resolution records similar to those in StatefulSet.

Forcing changes to the Go standard library implementation

There are some singleton implementations in the Go standard library, such as the default Logger and net.DefaultResolver in the log package, which provide convenient methods, but there are times when we need to do some customization and need to change these objects. There are even times when we need to change specific methods of the standard library, and the conventional means do not work, we must use some “hacking” methods.

How to ensure no data loss during power down in File IO

It’s been a long time since I’ve shared tips on file IO, and I vaguely remember the last time I did so. Kirito is also working on the topic “RocketMQ Storage System Design for Hot and Cold Read/Write Scenarios”, but we are participating in the internal track, so we can’t rank with our external partners. As we all know, storage design is inseparable from file IO, and storing data in files for persistence is a regular operation in most message queues and database systems.

Notes on using HeapByteBuffer for in-heap memory

Today we share a pitfall that many people tend to step in: the use of HeapByteBuffer. ByteBuffer has two main implementation classes HeapByteBuffer In-heap memory DirectByteBuffer Off-heap memory In my personal experience, I tend to use DirectByteBuffer in most cases, both for read and write operations, mainly because HeapByteBuffer may have some unexpected internal operations when interacting with FileChannel, which is the caveat mentioned in the title of this article, so let’s sell it here.

More than 100,000 words of detailed analysis of the implementation principle of Stream in the JDK

Prerequisites Stream was first introduced in JDK1.8, nearly 8 years ago (JDK1.8 was released at the end of 2013), and the introduction of Stream greatly simplified some development scenarios, but on the other hand, it may have reduced the readability of the code (it is true that many people say that Stream will reduce the readability of the code, but in my opinion, the readability of the code is improved

Talking about package managers yarn and npm

In the past, a simple text editor was sufficient for developers to create and manage most projects. But the WEB has changed radically since then, and today, even a fairly simple project usually has hundreds of scripts with complex nested dependencies that simply can’t be managed in an orderly fashion without an automation tool, which is where a package manager comes into play. A package manager is a tool that automates the handling of project dependencies in various ways.

Pipeable Programming in C++

Pipeable Pipeable is perhaps a rather controversial way of programming C++. There is pipeable in Boost: pipeable - Boost.HigherOrderFunctions 0.6 documentation - master. It is a part of the hof library 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <boost/hof.hpp> #include <cassert> using namespace boost::hof; struct sum { template<class T, class U> T operator()(T x, U y) const { return x+y; } }; int main() { assert(3 == (1 | pipable(sum())(2))); assert(3 == pipable(sum())(1, 2)); } The HOF library stands for Higher-order functions for C++, and its author Paul Fultz II is also a celebrity.

Cplusplus 17 Visitor Pattern

Visitor Pattern The accessor pattern is a behavioral pattern that allows arbitrary detached visitors to be able to access managed elements under the control of the manager. The visitor cannot change the definition of the object (but this is not mandatory, you can agree to allow changes). For the manager, it does not care how many visitors there actually are, it only cares about a defined order of access to the elements (for example, for a binary tree, you can provide multiple access orders such as mid-order, pre-order, etc.

Observer mode in C++17

Observer Pattern The Observer pattern is a behavioral pattern that is a subscription-publishing mechanism. Objects are able to make announcements, and anyone who has registered observer status with the object will be able to receive notifications when such announcement events occur. Registering an identity means subscribing, and the event occurs means publishing. There can be many observers doing subscriptions, at which point an observer chain is held in the observed

Golang http.Server graceful exit: the easily misused Shutdown() method

Writing an HTTP service in Go is easy, but getting a running service to exit safely is not so straightforward. If you are new to the term graceful shutdown, it refers to an HTTP service that stops accepting new requests after receiving a user’s exit command, and then actively exits after processing and responding to the batch of requests it is currently processing. Unlike SIGKILL (kill -9 or force stop),

The Strategy pattern in C++17

Strategy Pattern Route planning for two points on a map is a typical strategy mode application scenario. When we do a start to finish route planning, we expect the map to give us the best route for these modes: walking. Public transit, driving. Sometimes it may be subdivided into several strategies such as transit (rail priority), bus (transfer priority), etc. Standard work Following our construction convention, here is a framework code for path planning

Lua + Redis does dynamic routing to nginx

Since FastDFS distributed file storage does not retain the original file name when uploading files, when the file is uploaded it returns a file ID in the following format, which contains the group the file is in, the secondary directory, and a base64-encoded file name generated from the client’s IP, timestamp, and file size. The file ID is stored in the client database and can only be accessed by the

Docker Deployment FastDFS

If your FastDFS file system needs high availability and needs to be deployed on multiple machines, and you only run FastDFS on these servers, then FastDFS may not be suitable for deployment with Docker, it can be deployed directly on the machines according to the official documentation, there is no need to use containers to deploy. In fact, FastDFS is not suitable for containerized deployment, because the tracker server reports