dmx7 发布的文章

写好的程序放到linux服务器,隔几天上服务器一看,内存直接爆了。

本地buid程序测试,内存也是一下子升到几个G,开发的时候一直用的是goland,没发现这个问题。

1、把time.After改成time.NewTimer,发现没效果

2、 用 net/http/pprof 分析,刚开始觉得是太多http请求引起的 http client 内存泄漏,网上研究了好多资料,对 http client 参数也是做各种修改,搞了一天,无果。

3、 golang项目中的issues搜索 "http client memory leak",无意间看到 https://github.com/golang/go/issues/63276, 把 go build -race 中的 -race 删除,内存不飙升了,问题解决。

4、再去搜索 "go build -race" 就看到 https://go.dev/doc/articles/race_detector 这篇文章,最后面有说生产环境使用 go build -race 构建可能会让内存无限增长。

1、 通过 "cat /proc/sys/fs/nr_open" 查看系统限制,ulimit设置不能超过这个限制,通过"ulimit -n"查看当前限制
cat /proc/sys/fs/nr_open
ulimit -n
2、 通过 "ulimit -n 1000000"修改为100万
ulimit -n 1000000
3、 永久生效
echo 'root soft nofile 1000000' >> /etc/security/limits.conf
echo 'root hard nofile 1000000' >> /etc/security/limits.conf
echo '* soft nofile 1000000' >> /etc/security/limits.conf
echo '* hard nofile 1000000' >> /etc/security/limits.conf

第 1 步:yarn镜像配置

yarn config set registry https://registry.npmmirror.com -g
yarn config set disturl https://npmmirror.com/dist -g
yarn config set electron_mirror https://npmmirror.com/mirrors/electron/ -g
yarn config set sass_binary_site https://npmmirror.com/mirrors/node-sass/ -g
yarn config set phantomjs_cdnurl https://npmmirror.com/mirrors/phantomjs/ -g
yarn config set chromedriver_cdnurl https://cdn.npmmirror.com/dist/chromedriver -g
yarn config set operadriver_cdnurl https://cdn.npmmirror.com/dist/operadriver -g
yarn config set fse_binary_host_mirror https://npmmirror.com/mirrors/fsevents -g

第 2 步:创建新应用程序

yarn create electron-app projectname --template=vite

- 阅读剩余部分 -

使用 update-alternatives 进行版本切换

一、 创建 phpv.sh 文件

#!/bin/bash

VERSION=$1

if [ -z "$VERSION" ];then
  echo "请输入要切换的PHP版本"
  echo "可用版本列表: $(dir /etc/php)"
  echo "当前版本信息:"
  php -v
  exit
fi

sudo update-alternatives --set php /usr/bin/php${VERSION}

php -v

二、 添加执行权限

chmod+x phpv.sh

三、 创建别名, .profile 增加如下代码

alias phpv='/home/用户目录/script/phpv.sh'

使用Docker Desktop配置好本地PHP开发环境,发现打开一个链接都要花上好几秒时间,研究发现原因在于把本地项目文件挂载到容器中,但是Windows文件挂载到WSL2文件I/O性能非常差,这就是慢的原因。

不要使用 Docker Desktop,安装WSL2,把WSL2当服务器使用,在里面安装Docker,项目文件也不要放在Windows目录,直接放WSL2里面,性能飞起。