我为什么不再写博客?

以前是一个月可能会写一篇博客,后来是半年,现在可能一年都不怎么打开我的博客网站了。

每年都4月份要为此网站续费,让我知道,哦,原来我有个博客还在。

为什么不写?实在是没什么好写的。

也许是逐渐变得不愿意分享,不容易被感动的人,这些年,有很多事情发生了,但是好像都是按部就班的,或许就是太忙了,写博客不是生活必须的一部份,好好工作,处理好与家人的关系才是。

我逐渐失去了自我?也许我本来就没有拥有过这些?

总之,我不写博客这件事,也不是什么大事。

业界良心!用开源项目免费申请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