睡眠质量

这段时间以来睡眠质量很不错,得益于温馨的睡眠环境和轻松的心情。然后由于明天也要体检,我也在控制饮食,力求将体检数据做的好看些。

睡眠看似是一件小事,但它的的确确会影响生活和工作的方方面面,如果你有睡眠问题,希望你也能现在开始尝试设定健康的睡眠计划。

我计划工作日早上写一篇短文

按照目前的作息方式,出勤张江时,我8点半即可到公司楼下,吃完早餐(迅速一些)后,我在办公室可以有差不多半个小时的个人时间。

这段时间我会看一下阮一峰老师的《科技爱好者周刊》,当没有更新时,也会上v2ex论坛刷刷帖子。这种行为更多的是一种消遣,沉淀写来的内容微乎其微,尤其是v2ex论坛,其中充斥很多戾气满满的回复。

我决定如有时间充裕,减少以上两者的次数,以便可以在我的博客里写下我的每日所思所想。

以上。

业界良心!用开源项目免费申请JetBrains的 license 一天内通过

我这里的 License 是 All PACK 的,意味着目前我可以使用 jetbrains 的所有 IDE 一年,包括但不限于 PHPstorm, IDEA, PyCharm, GOLand。

光一个 PHPStorm 原价都要1200一年,曾经打半价活动时花了600买了一年,后来用的某个前同事给的教育版账号,恰好今天过期了,就想尝试一下使用开源项目申请,没想到处理速度这么快!

我用的这个项目申请的: https://github.com/yeskn-studio/vmoex-framework

非常感谢 JB,PHPstorm 真的非常好用!有空我将会在自己的博客和其他项目上加上 jb 的logo和链接,算是支持吧!

截图纪念:image-20200826213743480

如果你也有认为比较满意的项目,也可以在 jb 的官网申请试试~ 申请链接:https://www.jetbrains.com/shop/eform/opensource

不再用114DNS

最近用 postman 调试外部的一些 API,发现经常会失败,提示cant’t resole host 啥的,想想似乎是 DNS 解析干的事,于是看了一下自己 mac 上的 DNS,把114优先换成阿里云的:

image-20200825132831468

从上到下分别是:阿里DNS,上海电信 DNS,CF,谷歌。

使用 dig 命令测试发现效果还不错(关键信息已经打码):

➔ dig @223.5.5.5 myhost.com

; <<>> DiG 9.10.6 <<>> @223.5.5.5 myhost.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 64554
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;myhost.com.    IN  A

;; AUTHORITY SECTION:
com.            443 IN  SOA a.gtld-servers.net. nstld.verisign-grs.com. 1598332825 1800 900 604800 86400

;; Query time: 14 msec
;; SERVER: 223.5.5.5#53(223.5.5.5)
;; WHEN: Tue Aug 25 13:24:21 CST 2020
;; MSG SIZE  rcvd: 118

PHP7.4启用opcache并进行基准测试

启用

/path/to/7.4/php.ini

[opcache]

zend_extension=opcache.so

; 1.启用,默认禁用
opcache.enable=1

; 是否用于cli,同opcache.enable
opcache.enable_cli=1

; 由于我希望在php-fpm启动后,不检查文件的变化(减少没必要的资源开支),这里我设置为0;如果设置为1,那么opcache.revalidate_freq生效
opcache.validate_timestamps=0

; 注意这里我注释了,1.表示每秒检查文件变化,0表示每个请求都检查文件变化
; opcache.revalidate_freq=2

重启php-fpm:

kill -usr2 $(cat /path/to/php-fpm@7.4.pid)

使用ab命令测试效果

这是我的测试代码:

// plus.php
<?php

for($i=0, $total = 0;$i<=10000000;$i++){
    $total += $i;
}

echo $total;

ab命令如下:

ab -c 5 -n 50 'https://blog.yeskn.com/plus.php'

开启之前:

Document Path:          /plus.php
Document Length:        14 bytes

Concurrency Level:      5
Time taken for tests:   3.745 seconds
Complete requests:      50
Failed requests:        0
Total transferred:      7800 bytes
HTML transferred:       700 bytes
Requests per second:    13.35 [#/sec] (mean)
Time per request:       374.523 [ms] (mean)
Time per request:       74.905 [ms] (mean, across all concurrent requests)
Transfer rate:          2.03 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       27   34   3.9     33      43
Processing:   147  317  74.9    300     443
Waiting:      146  317  74.9    300     443
Total:        189  350  74.7    333     476

Percentage of the requests served within a certain time (ms)
  50%    333
  66%    389
  75%    418
  80%    435
  90%    469
  95%    471
  98%    476
  99%    476
 100%    476 (longest request)

开启之后:

Document Path:          /plus.php
Document Length:        14 bytes

Concurrency Level:      5
Time taken for tests:   2.467 seconds
Complete requests:      50
Failed requests:        0
Total transferred:      7800 bytes
HTML transferred:       700 bytes
Requests per second:    20.27 [#/sec] (mean)
Time per request:       246.721 [ms] (mean)
Time per request:       49.344 [ms] (mean, across all concurrent requests)
Transfer rate:          3.09 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       27   34   4.6     33      47
Processing:   102  197  52.4    188     295
Waiting:      101  197  52.4    188     295
Total:        135  231  52.2    229     327

Percentage of the requests served within a certain time (ms)
  50%    229
  66%    266
  75%    279
  80%    285
  90%    300
  95%    311
  98%    327
  99%    327
 100%    327 (longest request)

可以看到,QPS提升了大概0.5倍,并且速度提升很大,启用opcache后,最慢的请求只有327ms,没启用时,50%的请求都要大于333ms,提升效果显著。

以上测试用的是默认配置,如果进行合理的配置,我相信优化会更加明显!

systemd 清理不必要的service

执行systemctl status时,发现如下输出:

➔ systemctl status
● hostname
    State: degraded
     Jobs: 0 queued
   Failed: 1 units
    Since: Tue 2018-10-30 06:51:31 CST; 1 years 9 months ago
   CGroup: /
           ├─1 /usr/lib/systemd/systemd --system --deserialize 21

state的状态是degraded,查了一下发现是由于我的nginx service未启动,因为前几天手动编译安装了nginx,并且新建了一个nginx@1.18.service,所以这个service其实没用到了,把它清理掉吧:

systemctl stop [servicename]
systemctl disable [servicename]
rm /etc/systemd/system/[servicename]
rm /etc/systemd/system/[servicename] # and symlinks that might be related
rm /usr/lib/systemd/system/[servicename] 
rm /usr/lib/systemd/system/[servicename] # and symlinks that might be related
systemctl daemon-reload
systemctl reset-failed

编译安装PHP扩展:imagick

由于wordpress建议安装imagick,而它默认没有加入到php源码中,于是记录一下自己编译安装imagick扩展的过程:

wget https://pecl.php.net/get/imagick-3.4.4.tgz
tar -xvf imagick-3.4.4.tgz && cd imagick-3.4.4

/usr/local/opt/php@7.4/bin/phpize

# 这个目录似乎没用到
mkdir /usr/local/opt/imagick

./configure --prefix=/usr/local/opt/imagick --with-php-config=/usr/local/opt/php@7.4/bin/php-config

报错:

checking ImageMagick MagickWand API configuration program... checking Testing /usr/local/bin/MagickWand-config... Doesn't exist
checking Testing /usr/bin/MagickWand-config... Doesn't exist
checking Testing /usr/sbin/bin/MagickWand-config... Doesn't exist
checking Testing /opt/bin/MagickWand-config... Doesn't exist
checking Testing /opt/local/bin/MagickWand-config... Doesn't exist
configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.

解决办法:

yum install -y ImageMagick-devel

最后:

make && make install

vi /usr/local/etc/php/7.4/php.ini

# 在最后加入:
extension=imagick.so

# 查看是否OK:
/usr/local/opt/php@7.4/bin/php -m | grep imagick

重启php-fpm生效:

systemctl restart php-fpm@7.4