Context包
在Go 1.7中,context包被引入到标准库中。 context是处理并发问题的一个标准风格。
context包内容很简单:
var Canceled = errors.New("context canceled")
var DeadlineExceeded error = deadlineExceededError{}
func WithCancel(parent Context) (ctx Context, cancel CancelFunc)
func WithDeadline(parent Context, d time.Time) (Context, CancelFunc)
func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc)
type CancelFunc func()
type Context interface{ ... }
func Background() Context
func TODO() Context
func WithValue(parent Context, key, val interface{}) Context
在使用context包的过程中,不应该Context存储在struct中,而是将Context作为参数传递给需要它的函数。不能传递nil Context,如果不确定该使用什么样的Context,那么传递context.TODO。
Golang和假共享(false sharing)
Golang和假共享(false sharing)
多核处理器(SMP)系统中, 每一个处理器都有一个本地高速缓存。内存系统必须保证高速缓存的一致性。当不同处理器上的线程修改驻留再同一高速缓存中的变量时就会发生假共享(false sharing),结果导致高速缓存无效,并强制更新,进而影响系统性能。
本地Docker加载阿里Mysql物理备份
前言
将阿里云数据库物理备份的数据下载到本地,使用Docker来加载,来做数据升级和迁移的本地测试。
HOW TO
-
将线上数据库物理备份,并下载到本地
如下载后放置在~/Downloads/hins4577021_data_20181203163125.tar
-
将数据库备份文件解压, 如:
mkdir -p ~/Downloads/data
cd ~/Downloads
tar -xvf hins4577021_data_20181203163125.tar -C ./data
- 使用mysql 5.7 docker镜像,加载数据备份数据
docker run --name some-mysql -v "$PWD/data":/var/lib/mysql -e MYSQL_ROOT_PASSWORD=go -p 3306:3306 -d mysql:5.7
# 查看运行的容器
docker ps 0 [10:51:06]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0a128332fe96 mysql:5.7 "docker-entrypoint.s…" 10 minutes ago Up 10 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp some-mysql
- 连接数据库(使用线上数据库的用户名和密码)
mysql -h 127.0.0.1 -P3306 -u saas -p 0 [10:50:02]
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
使用shell给文件每一行添加行号
使用shell给文件每一行添加行号,
如原始文件:
AAA
BB
C
输出文件:
1 AAA
2 BB
3 C
kubectl集群访问环境配置
kubectl访问集群环境配置
替换git远程仓库
- commit本地所有更改, 并更新本地代码到最新版本
git pull --all
Yarn淘宝镜像
NPM设置淘宝镜像
1.查询当前配置的镜像
npm get registry
设置成淘宝镜像
npm config set registry http://registry.npm.taobao.org/
Git_emoji
在git commit信息中使用emoji,提供一种简单的方法来识别提交的目的或意图: 只需要查看使用的emoji符号。在提交的历史中也更容易区分和查找。更多信息参见gitmoji。

K8s常用命令