西维蜀黍

【Linux】命令 - ssh

通过 SSH 执行命令

查看远程主机是否运行进程httpd:

$ ssh user@host 'ps ax | grep [h]ttpd'

Demo

-p - 指定连接端口

Port to connect to on the remote host. This can be specified on a per-host basis in the configuration file.

Example

SSH默认端口是22。大多现代的Linux系统22端口是开放的。如果你运行ssh程序而没有指定端口号,它直接就是通过22端口发送请求。

一些系统管理员会改变SSH的默认端口号。让我们试试,现在端口号是1234。要连上主机,就要使用**-p**选项,后面再加上SSH端口

$ ssh 192.168.1.1 -p 1234

要改变端口号,我们需要修改/etc/ssh/ssh_config文件,找到此行:

Port 22

把它换成其他端口号,比如上面的1234.然后重启SSH服务。

  ...


【Network】Speedtest CLI 测速

macOS

brew tap teamookla/speedtest
brew update
brew install speedtest --force

Ubuntu

sudo apt-get install gnupg1 apt-transport-https dirmngr
export INSTALL_KEY=379CE192D401AB61
# Ubuntu versions supported: xenial, bionic
# Debian versions supported: jessie, stretch, buster
export DEB_DISTRO=$(lsb_release -sc)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $INSTALL_KEY
echo "deb https://ookla.bintray.com/debian ${DEB_DISTRO} main" | sudo tee  /etc/apt/sources.list.d/speedtest.list
sudo apt-get update
# Other non-official binaries will conflict with Speedtest CLI
# Example how to remove using apt-get
# sudo apt-get remove speedtest-cli
sudo apt-get install speedtest
  ...


【MySQL】EXPLAIN 使用

EXPLAIN

The EXPLAIN statement provides information about how MySQL executes statements. EXPLAIN works with SELECT, DELETE, INSERT, REPLACE, and UPDATE statements.

EXPLAIN returns a row of information for each table used in the SELECT statement. It lists the tables in the output in the order that MySQL would read them while processing the statement. MySQL resolves all joins using a nested-loop join method. This means that MySQL reads a row from the first table, and then finds a matching row in the second table, the third table, and so on. When all tables are processed, MySQL outputs the selected columns and backtracks through the table list until a table is found for which there are more matching rows. The next row is read from this table and the process continues with the next table.

  ...


【MySQL】查询结果顺序问题

Answer

In the SQL world, order is not an inherent property of a set of data. Thus, you get no guarantees from your RDBMS that your data will come back in a certain order – or even in a consistent order – unless you query your data with an ORDER BY clause.

  ...


【Linux】配置本地DNS

Linux

Under Linux / UNIX / BSD operating system, you need to edit the /etc/resolv.conf file and add the line:

nameserver {IP-OF-THE-DNS-1}
nameserver {IP-OF-THEISP-DNS-SERVER-2}

Login as the root, enter:

# vi /etc/resolv.conf

OR

$ sudo vi /etc/resolv.conf

Modify or enter nameserver as follows:

nameserver 208.67.222.222
nameserver 208.67.220.220
  ...


【Golang】性能调优 - trace

Tracing

trace 工具可以看到GC被执行的次数和每次执行的时长

Tracing is a way to instrument code to analyze latency throughout the lifecycle of a chain of calls. Go provides golang.org/x/net/trace package as a minimal tracing backend per Go node and provides a minimal instrumentation library with a simple dashboard. Go also provides an execution tracer to trace the runtime events within an interval.

Tracing enables us to:

  • Instrument and analyze application latency in a Go process.
  • Measure the cost of specific calls in a long chain of calls.
  • Figure out the utilization and performance improvements. Bottlenecks are not always obvious without tracing data.
  ...


【Golang】性能调优 - 分析阻塞操作

排查因调用同步原语(synchronization primitives)导致阻塞操作

使用前需要先调用 runtime.SetMutexProfileFraction

在程序中,除了锁的争用会导致阻塞之外,很多逻辑都会导致阻塞。

  ...


【Golang】性能调优 - 分析互斥锁使用

查看因持有互斥锁(mutexes)导致阻塞的情况(堆栈)

使用前需要先调用 runtime.SetBlockProfileRate

$ go tool pprof http://localhost:6060/debug/pprof/mutex
Fetching profile over HTTP from http://localhost:6060/debug/pprof/mutex
Saved profile in /Users/weishi/pprof/pprof.contentions.delay.002.pb.gz
Type: delay
Time: Aug 15, 2020 at 1:54pm (+08)
No samples were found with the default sample value type.
Try "sample_index" command to analyze different sample values.
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
Showing nodes accounting for 0, 0% of 0 total
      flat  flat%   sum%        cum   cum%
  ...


【Golang】性能调优 - 分析 goroutine 使用

排查 goroutine 泄露

由于 Golang 自带内存回收,所以一般不会发生内存泄露。但凡事都有例外,在 golang 中, goroutine 本身是可能泄露的,或者叫 goroutine 失控,进而导致内存泄露。

  ...


【Golang】性能调优 - 性能诊断

Diagnostics solutions can be categorized into the following groups:

  • Profiling: Profiling tools analyze the complexity and costs of a Go program such as its memory usage and frequently called functions to identify the expensive sections of a Go program.
  • Tracing: Tracing is a way to instrument code to analyze latency throughout the lifecycle of a call or user request. Traces provide an overview of how much latency each component contributes to the overall latency in a system. Traces can span multiple Go processes.
  • Debugging: Debugging allows us to pause a Go program and examine its execution. Program state and flow can be verified with debugging.
  • Runtime statistics and events: Collection and analysis of runtime stats and events provides a high-level overview of the health of Go programs. Spikes/dips of metrics helps us to identify changes in throughput, utilization, and performance.
  ...