西维蜀黍

【Performance】Linux 性能问题调优 - I/O

查看 I/O

如果CPU利用率不高,但是系统的Throughput和Latency上不去了,这说明我们的程序并没有忙于计算,而是忙于别的一些事,比如IO。(另外,CPU的利用率还要看内核态的和用户态的,内核态的一上去了,整个系统的性能就下来了。而对于多核CPU来说,CPU 0 是相当关键的,如果CPU 0的负载高,那么会影响其它核的性能,因为CPU各核间是需要有调度的,这靠CPU0完成)

网络

Refer to https://swsmile.info/post/performance-network-diagnose/.

iostat

iostat是I/O statistics(输入/输出统计)的缩写,iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息。用户可以通过指定统计的次数和时间来获得所需的统计信息。

  ...


【MySQL】学习

MySQL 的功能模块

下面我给出的是 MySQL 的基本架构示意图,从中你可以清楚地看到 SQL 语句在 MySQL 的各个功能模块中的执行过程。

大体来说,MySQL 可以分为 Server 层和存储引擎层两部分。

  ...


【Distributed System】架构学习

基本概念

包括:系统与子系统、模块与组件、框架与架构。

系统与子系统

我们先来看维基百科定义的“系统”。系统泛指由一群有关联的个体组成,根据某种规则运作,能完成个别元件不能单独完成的工作的群体。它的意思是“总体”“整体”或“联盟”。

我来提炼一下里面的关键内容:

  • 关联:系统是由一群有关联的个体组成的,没有关联的个体堆在一起不能成为一个系统。例如,把一个发动机和一台 PC 放在一起不能称之为一个系统,把发动机、底盘、轮胎、车架组合起来才能成为一台汽车。
  • 规则:系统内的个体需要按照指定的规则运作,而不是单个个体各自为政。规则规定了系统内个体分工和协作的方式。例如,汽车发动机负责产生动力,然后通过变速器和传动轴,将动力输出到车轮上,从而驱动汽车前进。
  • 能力:系统能力与个体能力有本质的差别,系统能力不是个体能力之和,而是产生了新的能力。例如,汽车能够载重前进,而发动机、变速器、传动轴、车轮本身都不具备这样的能力。
  ...


【Distributed System】无服务器(Serverless)

什么是无服务器计算?

“无服务器”是云计算中资源抽象的极致体现。从它的命名上你就可以看出,所谓“无服务器”就是想让用户感觉不到服务器的存在,这是因为有一朵巨大的云在底层进行着支撑。这样你可以完全专注于业务逻辑的编写,而不再关心任何基础设施。

我们在前面课程的讨论中,其实已经接触到了一些广义上的无服务器 PaaS 服务,比如第 13 讲中的无服务器查询服务和第 14 讲中的无服务器容器服务。甚至第 9 讲中的对象存储服务,它理论上来说也是符合无服务器特征的,因为你不用关心究竟是什么样的机器和多少机器在背后支撑它。

今天我们要来专门讨论的,是经典的无服务器计算服务(Serverless Computing)。“无服务器”这个名称,就是从这种灵活的计算服务起源的。

如果把无服务器计算和容器类服务一起比较的话,这两种云上计算类服务有着共同的优势和特点,比如说,它们都支持细粒度封装和易于大规模扩展。但这两者也有很不一样的地方。

如果说容器是给予了我们很大的定制空间,让你更加容易地按照自己的需要,来进行应用程序的拆分和封装;那么无服务器则是完全屏蔽了计算资源,它是在真正地引导你不再去关心底层环境,你只要遵循标准方式来直接编写业务代码就可以了。

而且在粒度上,无服务器会允许你拆分得更细致、更轻量。你甚至可以把每一个具有独立功能的函数,来作为一个单独的服务进行部署和运行。这也是为什么,在有些云计算的分类方法下,无服务器计算能够单独“开宗立派”,被称为**函数即服务(Function-as-a-Service,FaaS)**的原因。

  ...


【Network】网络测速工具 - iperf3

iperf3

iperf is a tool for active measurements of the maximum achievable bandwidth on IP networks. It supports tuning of various parameters related to timing, protocols, and buffers. For each test it reports the measured throughput / bitrate, loss, and other parameters.

Usage

# server
$ iperf3 -s -p 1020

# client
iperf3 -c 127.0.0.1 -p 1020
Connecting to host 127.0.0.1, port 1020
[  5] local 127.0.0.1 port 51841 connected to 127.0.0.1 port 1020
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec  5.51 GBytes  47.3 Gbits/sec
[  5]   1.00-2.00   sec  5.57 GBytes  47.8 Gbits/sec
[  5]   2.00-3.00   sec  5.44 GBytes  46.7 Gbits/sec
[  5]   3.00-4.00   sec  6.23 GBytes  53.5 Gbits/sec
[  5]   4.00-5.00   sec  6.17 GBytes  53.0 Gbits/sec
[  5]   5.00-6.00   sec  6.11 GBytes  52.5 Gbits/sec
[  5]   6.00-7.00   sec  6.23 GBytes  53.5 Gbits/sec
[  5]   7.00-8.00   sec  6.14 GBytes  52.7 Gbits/sec
[  5]   8.00-9.00   sec  6.17 GBytes  53.0 Gbits/sec
[  5]   9.00-10.00  sec  6.13 GBytes  52.6 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.00  sec  59.7 GBytes  51.3 Gbits/sec                  sender
[  5]   0.00-10.00  sec  59.7 GBytes  51.3 Gbits/sec                  receiver

iperf Done.
  • -p [port]:指定端口
  • -u:使用UDP
  • -b [target bitrate] :target bitrate in bits/sec (0 for unlimited) (default 1 Mbit/sec for UDP, unlimited for TCP)
  • -t [duration]:time in seconds to transmit for (default 10 secs)
  ...


【Golang】使用 - JSON序列化与反序列化

struct转JSON

我们可以在struct的attribute后指定该struct被序列化成JSON后的key的值,这被称为Struct Tag

Struct tag 可以决定 Marshal 和 Unmarshal 函数如何在序列化和反序列化数据时,JSON key的值。

如果没有指定,则取该attribute对应全小写字符串作为key的值。

package main

import (
	"encoding/json"
	"fmt"
)

type User struct {
	UserName string `json:"username"`
	NickName string `json:"nickname"`
	Age      int
	Birthday string `json:"birth"`
	Sex      string
	Email    string
	Phone    string
}

/*结构体转json*/
func testStruct() {
	user1 := &User{
		UserName: "user1",
		NickName: "上课看似",
		Age:      18,
		Birthday: "2008/8/8",
		Sex:      "男",
		Email:    "mahuateng@qq.com",
		Phone:    "110",
	}

	dataBytes, err := json.Marshal(user1)
	if err != nil {
		fmt.Printf("json.marshal failed, err:", err)
		return
	}

	fmt.Printf("%s \n", string(dataBytes))
}

func main() {
	testStruct()
	fmt.Println("----")
}

//output
{"username":"user1","nickname":"上课看似","Age":18,"birth":"2008/8/8","Sex":"男","Email":"mahuateng@qq.com","Phone":"110"} 
----
  ...


【MySQL】用户和权限管理

MySQL权限

关于MySQL的权限简单的理解就是MySQL允许你做你全力以内的事情,不可以越界。比如只允许你执行select操作,那么你就不能执行update操作。只允许你从某台机器上连接MySQL,那么你就不能从除那台机器以外的其他机器连接MySQL。

那么MySQL的权限是如何实现的呢?这就要说到MySQL的两阶段验证,下面详细介绍:

  • 第一阶段:服务器首先会检查你是否允许连接。因为创建用户的时候会加上主机限制,可以限制成本地、某个IP、某个IP段、以及任何地方等,只允许你从配置的指定地方登陆。
  • 第二阶段:如果你能连接,MySQL会检查你发出的每个请求,看你是否有足够的权限实施它。比如你要更新某个表、或者查询某个表,Mysql会查看你对哪个表或者某个列是否有权限。再比如,你要运行某个存储过程,MySQL会检查你对存储过程是否有执行权限等。
  ...


【MySQL】MySQL安全性设置

  ...


【MySQL】Establishing a Database Connection

  ...


【Golang】Set实现

Interface

type Set interface {
	// Adds an element to the set. Returns whether
	// the item was added.
	Add(i interface{}) bool

	// Returns the number of elements in the set.
	Cardinality() int

	// Removes all elements from the set, leaving
	// the empty set.
	Clear()

	// Returns a clone of the set using the same
	// implementation, duplicating all keys.
	Clone() Set

	// Returns whether the given items
	// are all in the set.
	Contains(i ...interface{}) bool

	// Returns the difference between this set
	// and other. The returned set will contain
	// all elements of this set that are not also
	// elements of other.
	//
	// Note that the argument to Difference
	// must be of the same type as the receiver
	// of the method. Otherwise, Difference will
	// panic.
	Difference(other Set) Set

	// Determines if two sets are equal to each
	// other. If they have the same cardinality
	// and contain the same elements, they are
	// considered equal. The order in which
	// the elements were added is irrelevant.
	//
	// Note that the argument to Equal must be
	// of the same type as the receiver of the
	// method. Otherwise, Equal will panic.
	Equal(other Set) bool

	// Returns a new set containing only the elements
	// that exist only in both sets.
	//
	// Note that the argument to Intersect
	// must be of the same type as the receiver
	// of the method. Otherwise, Intersect will
	// panic.
	Intersect(other Set) Set
	
	...
}	
  ...