跳转至

翻译

Nasm使用教程:基于X86编程教学

原文:NASM Tutorial

第一个程序

在了解 nasm 之前,让我们确保你可以输入和运行程序。确保 nasm 和 gcc 都已安装。根据你的机器平台,将以下程序之一保存为 hello.asm。然后根据给定的说明运行程序。

如果你使用的是基于 Linux 的操作系统:

; ----------------------------------------------------------------------------------------
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
; To assemble and run:
;
;     nasm -felf64 hello.asm && ld hello.o && ./a.out
; ----------------------------------------------------------------------------------------

          global    _start

          section   .text
_start:   mov       rax, 1                  ; system call for write
          mov       rdi, 1                  ; file handle 1 is stdout
          mov       rsi, message            ; address of string to output
          mov       rdx, 13                 ; number of bytes
          syscall                           ; invoke operating system to do the write
          mov       rax, 60                 ; system call for exit
          xor       rdi, rdi                ; exit code 0
          syscall                           ; invoke operating system to exit

          section   .data
message:  db        "Hello, World", 10      ; note the newline at the end

Go 开发中我一定会用到的 7 种代码模式

原文:7 Code Patterns in Go I Can’t Live Without

代码模式使你的程序更可靠、更高效,并使你的工作和生活更轻松

我已经为开发EDR解决方案工作了7年。这意味着我必须编写具有弹性和高效性的长时间运行的系统软件。我在这项工作中大量使用 Go,我想分享一些最重要的代码模式,你可以依靠这些模式你的程序更加可靠(reliable)和高效(efficient)。

使用Map实现Set

我们经常需要检查某些对象是否存在。例如,我们可能想检查之前是否访问过某个文件或者URL。在这些情况下,我们可以使用map[string]struct{}。如下所示:

使用空结构 struct{} 意味着我们不希望Map的值占用任何空间。有些人会使用 map[string]bool,但基准测试表明 map[string]struct{} 在内存和时间上都表现得更好。相关基准测试可以查看这里

探索Prometheus Go客户端指标

原文是 Exploring Prometheus Go client metrics,有删改。

在这篇文章中,我将探索下Prometheus Go 客户端指标,这些指标由client_go通过promhttp.Handler()暴露出来的。通过这些指标能帮助你更好的理解 Go 是如何工作的。

想对Prometheus了解更多吗?你可以去学习下Monitoring Systems and Services with Prometheus,这是一门很棒的课程,可以让你快速上手。

让我们从一个简单的程序开始,它注册prom handler并且监听8080端口:

package main

import (
    "log"
    "net/http"

    "github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {
    http.Handle("/metrics", promhttp.Handler())
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Go 反射三定律

原文地址:https://blog.golang.org/laws-of-reflection

简介

Reflection(反射) 在计算机中表示程序能够检查自身结构的能力,特别指通过类型进行处理。它是元编程的一种形式,也是最容易让人迷惑的一部分。

类型和接口

因为反射建立在类型系统之上,所以让我们先回顾一下 Go 中的类型。Go 是静态类型语言。每个变量都有一个静态类型,即只有一种类型,并且在编译时就已经确定了。比如int, float32, *MyType, []byte等。比如我们进行如下声明:

type MyInt int

var i int
var j MyInt

在Linux中如何使用logrotate管理日志

原文:How To Manage Log Files Using Logrotate In Linux

几天前,我们发布了一份指南,介绍了如何在CentOS系统上设置集中式Rsyslog服务。今天,在本指南中,我们将了解如何在Linux上使用日志轮换来管理日志文件。该实用程序简化了日志文件的管理,尤其适用于每天生成大量日志文件的系统。顾名思义,LogRotate以固定的时间间隔将日志完全从系统中轮转出来。它还允许日志文件的自动轮转、压缩、删除和传输。每个日志文件可以每天、每周、每月或在变得太大时处理。

《Nginx Cookbook 2019》中文版第三章流量管理

3.0 Introduction

NGINX and NGINX Plus are also classified as web traffic control‐ lers. You can use NGINX to intellengently route traffic and control flow based on many attributes. This chapter covers NGINX’s ability to split client requests based on percentages, utilize geographical location of the clients, and control the flow of traffic in the form of rate, connection, and bandwidth limiting. As you read through this chapter, keep in mind that you can mix and match these features to enable countless possibilities.

《Nginx Cookbook 2019》中文版第二章高性能负载均衡

2.0 Introduction-简介

Today’s internet user experience demands performance and uptime. To achieve this, multiple copies of the same system are run, and the load is distributed over them. As the load increases, another copy of the system can be brought online. This architecture technique is called horizontal scaling. Software-based infrastructure is increasing in popularity because of its flexibility, opening up a vast world of possibilities. Whether the use case is as small as a set of two for high availability or as large as thousands around the globe, there’s a need for a load-balancing solution that is as dynamic as the infrastructure. NGINX fills this need in a number of ways, such as HTTP, TCP, and UDP load balancing, which we cover in this chapter.

当今的互联网用户体验要求性能和时时在线。为了达到这个目的,同一个系统的多个副本需同时运行,并且将负载分布在这些副本上。随着负载的增加,系统的另一个副本可以联机。这种架构技术被称为水平拓展。基于软件的基础设施因其灵活性而越来越受欢迎,开辟了一个广阔的无限可能的世界。对于高可用性而言,用例小到两个,还是在全球范围内成千上万个,都需要一个与基础架构一样动态的负载均衡解决方案。NGINX以多种方式满足这一需求,我们在本章中将讨论超文本传输协议(HTTP)、TCP和UDP的负载平衡。

《Nginx Cookbook 2019》中文版第一章基础知识

0.0 最前面话

最近看了一本关于NGINX的电子书,编排形式比较新颖,通过一问一答的方式来告诉读者如何快速上手NGINX,以及处理真实项目中的需求。书的内容简练概括,但涉及面较多,内容有4层和7层负载均衡,A/B测试,自动化部署,认证,Http2,debug和调优等,有些示例可以拿来直接用。由于原书暂无中文译本,姑且尝试翻译一下,90%机器翻译,10%人工修正。原书信息如下:

1.0 Introduction-简介

To get started with NGINX Open Source or NGINX Plus, you first need to install it on a system and learn some basics. In this chapter you will learn how to install NGINX, where the main configuration files are, and commands for administration. You will also learn how to verify your installation and make requests to the default server.

要开始使用开源版NGINX或NGINX Plus,你首先需要将在操作系统里面安装上并学习一些相关的基础知识。在本章中,你将学习如何安装nginx,其主要配置文件所在位置,以及管理命令。你还将学习如何验你的安装并向默认服务器发送请求。

十种常见软件架构模式

原文地址:10 Common Software Architectural Patterns in a nutshell

是否曾经好奇过大型企业系统是如何设计的?在主要软件开发之前,我们需要选择合适的架构,为我们提供所需的功能和质量属性。因为,在我们应用架构到我们的设计中之前,我们应该了解不同的架构

Software Architectural Patterns

什么是架构模式?

架构模式是对给定上下文中软件架构中常见问题的通用、可重用的解决方案。架构模式类似于软件设计模式,但范围更广。