很荣幸通过龙芯官方申请到了龙芯云的体验资源,审核很快,大概几天过后就会有邮件发送过来了,这次申请到的服务器资源为龙芯3A4000的CPU
- CPU:Loongson-3A4000 vCPUs * 2
- RAM:8GB
- DISK:100GB
- OS:UOS Server 20
硬件信息概况:
root@loongson-PC:/home/loongcloud# lshw -short
H/W path Device Class Description
===================================================
system loongson,generic
/0 bus Motherboard
/0/0 processor ICT Loongson-3A R4 (Loongson-3A4000) @ 1800MHz
/0/1 processor ICT Loongson-3A R4 (Loongson-3A4000) @ 1800MHz
/0/2 processor CPU
/0/3 processor CPU
/0/4 processor CPU
/0/5 processor CPU
/0/6 memory 8GiB System memory
/0/100 bridge Hyper Transport Bridge Controller
/0/100/1 bus KeyLargo/Intrepid USB
/0/100/2 display QXL paravirtual graphic card
/0/100/3 network Virtio network device
/0/100/3/0 enp0s3 network Ethernet interface
/0/100/4 bus QEMU XHCI Host Controller
/0/100/5 communication Virtio console
/0/100/5/0 generic Virtual I/O device
/0/100/6 storage Virtio block device
/0/100/6/0 /dev/vda disk 53GB Virtual I/O device
/0/100/6/0/1 /dev/vda1 volume 299MiB Windows FAT volume
/0/100/6/0/2 /dev/vda2 volume 8001MiB swap partition
/0/100/6/0/3 /dev/vda3 volume 41GiB EXT4 volume
/0/100/7 generic Virtio memory balloon
/0/100/7/0 generic Virtual I/O device
一、初始化配置
1.1 更换镜像源
这里建议切换为bash,因为sh实在太难用
bash
首先龙芯云配置的镜像源是UOS20 Server的镜像源,但我死活无法apt更新网络一直报错,于是我更新为deepin20的镜像源
要换源首先要备份原来的镜像源:
cp /etc/apt/sources.list /etc/apt/sources.list.bak
然后编辑镜像源:
vim /etc/apt/sources.list
填入:
deepin 20 镜像源
## Generated by deepin-installer
deb [by-hash=force] https://community-packages.deepin.com/deepin/ apricot main contrib non-free
#deb-src https://community-packages.deepin.com/deepin/ apricot main contrib non-free
保存退出,并更新:
apt update && apt upgrade -y
然后发现deepin20的镜像源对于龙芯的MIPS64架构支持得不是很友好,许多包都没有,于是查询了一下,deepin20基于debian10,于是将源改成了debian10的镜像源,对于mips64的包就多了很多了
所以总结一下套壳顺序:UOS 20 -> Deepin 20 -> Debian 10
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
如果遇到无法拉取 https 源的情况,请先使用 http 源并安装:
sudo apt install apt-transport-https ca-certificates
保存退出,并更新:
apt update && apt upgrade -y
1.2 将loongcloud用户赋予sudo权限
编辑sudoers文件:
vim /etc/sudoers
从以下四个规则里面四选一:
loongcloud ALL=(ALL) ALL
%loongcloud ALL=(ALL) ALL
loongcloud ALL=(ALL) NOPASSWD: ALL
%loongcloud ALL=(ALL) NOPASSWD: ALL
- 允许用户loongcloud执行sudo命令(需要输入密码)
- 允许用户组loongcloud里面的用户执行sudo命令(需要输入密码)
- 允许用户loongcloud执行sudo命令,并且在执行的时候不输入密码
- 允许用户组loongcloud里面的用户执行sudo命令,并且在执行的时候不输入密码
我选择了第三种,对于个人用的机器比较方便,但是对于服务器安全性不太高
1.3 修改Python源
首先安装pip:
sudo apt install python-pip python3-pip -y
临时使用:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
注意,simple
不能少, 是 https
而不是 http
设为默认:
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
1.4 安装aptitude
aptitude与 apt-get 一样,是 Debian 及其衍生系统中功能极其强大的包管理工具。与 apt-get 不同的是,aptitude在处理依赖问题上更佳一些。举例来说,aptitude在删除一个包时,会同时删除本身所依赖的包。这样,系统中不会残留无用的包,整个系统更为干净。
简单来说就是可以解决很多奇怪的依赖问题,安装:
sudo apt install aptitude
使用aptitude的方法与apt的方法相同
因为龙芯云搭配UOS 20 Server并没有配置g++编译器,需要我们重新安装带g++版本的gcc:
sudo aptitude install g++
然后第一部选择n,降级包,然后选择y安装即可
1.5 安装tmux
mux是一个 terminal multiplexer(终端复用器),它可以启动一系列终端会话
我们使用命令行时,打开一个终端窗口,,会话开始,执行某些命令如npm run dev,关闭此终端窗口,会话结束,npm run dev服务会话随之被关闭。有时我们希望我们运行的服务如npm run dev 或者一些cd命令等,被保留,而不是关闭窗口再打开后,重新手动执行。tmux的主要用途就在于此
它解绑了会话和终端窗口。关闭终端窗口再打开,会话并不终止,而是继续运行在执行。将会话与终端窗后彻底分离
简单来说就是可以实现终端复用,安装:
sudo aptitude install tmux
1.6 安装wget、curl、npm
wget和curl都是常见的网络下载工具
不得不说龙芯版本的UOS 20 Server 连wget都没有是十分不方便的事情,还有g++编译器也没有,强烈建议以后要附加上,不然基本工具链都很麻烦
NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种:
- 允许用户从NPM服务器下载别人编写的第三方包到本地使用。
- 允许用户从NPM服务器下载并安装别人编写的命令行程序到本地使用。
- 允许用户将自己编写的包或命令行程序上传到NPM服务器供别人使用。
sudo aptitude install wget curl npm -y
1.7 更换默认shell
更换为bash:
sudo chsh -s $(which bash)
二、性能测试
这里的性能测试主要针对CPU性能本身,使用的工具是UnixBench
UnixBench是一个类 Unix 系(Unix,BSD,Linux)统下的性能测试工具,一个开源工具,被广泛用与测试 Linux 系统主机的性能。UnixBench 的主要测试项目有:系统调用、读写、进程、图形化测试、2D、3D、管道、运算、C库等系统基准性能提供测试数据
2.1测试项目
- Dhrystone 2 using register variables:此项用于测试 string handling,因为没有浮点操作,所以深受软件和硬件设计(hardware and software design)、编译和链接(compiler and linker options)、代码优化(code optimazaton)、对内存的cache(cache memory)、等待状态(wait states)、整数数据类型(integer data types)的影响
- Double-Precision Whetstone:这一项测试浮点数操作的速度和效率。这一测试包括几个模块,每个模块都包括一组用于科学计算的操作。覆盖面很广的一系列 c 函数:sin,cos,sqrt,exp,log 被用于整数和浮点数的数学运算、数组访问、条件分支(conditional branch)和程序调用。此测试同时测试了整数和浮点数算术运算
- Execl Throughput:此测试考察每秒钟可以执行的 execl 系统调用的次数。 execl 系统调用是 exec 函数族的一员。它和其他一些与之相似的命令一样是 execve() 函数的前端
- File copy:测试从一个文件向另外一个文件传输数据的速率。每次测试使用不同大小的缓冲区。这一针对文件 read、write、copy 操作的测试统计规定时间(默认是 10s)内的文件 read、write、copy 操作次数
- Pipe Throughput:管道(pipe)是进程间交流的最简单方式,这里的 Pipe throughtput 指的是一秒钟内一个进程可以向一个管道写 512 字节数据然后再读回的次数。需要注意的是,pipe throughtput 在实际编程中没有对应的真实存在
- Pipe-based Context Switching:这个测试两个进程(每秒钟)通过一个管道交换一个不断增长的整数的次数。这一点很向现实编程中的一些应用,这个测试程序首先创建一个子进程,再和这个子进程进行双向的管道传输
- Process Creation:测试每秒钟一个进程可以创建子进程然后收回子进程的次数(子进程一定立即退出)。process creation 的关注点是新进程进程控制块(process control block)的创建和内存分配,即一针见血地关注内存带宽。一般说来,这个测试被用于对操作系统进程创建这一系统调用的不同实现的比较
- System Call Overhead:测试进入和离开操作系统内核的代价,即一次系统调用的代价。它利用一个反复地调用 getpid 函数的小程序达到此目的
- Shell Scripts:测试一秒钟内一个进程可以并发地开始一个 shell 脚本的 n 个拷贝的次数,n 一般取值 1,2,4,8。(我在测试时取 1, 8)。这个脚本对一个数据文件进行一系列的变形操作(transformation)
2.2 下载
在GitHub上可以获取到所有的源代码,来自行编译
git clone https://github.com/kdlucas/byte-unixbench.git
1
2.3 编译
预选项:
sed -i 's/-mtune=native//' Makefile
sed -i 's/-march=native//' Makefile
sed -i 's/$field eq "bogomips"/$field eq "bogomips" or $field eq "BogoMIPS" /g' Run
CPU整型跑分指令:
./Run -c 1 dhry2reg
CPU浮点型跑分指令:
./Run -c 1 whetstone
2.4 分数
这里使用另外两台VPS的不同架构的CPU作为对比:
- 腾讯云:Intel® Xeon® Gold 6148 CPU @ 2.40GHz
- 华为云:Huawei Kunpeng 920
这里主要测试单核性能,因为腾讯云的服务器只有一个核心
型号 | 整型 | 浮点 |
---|---|---|
Loongson-3A4000 | 1100.3 | 377.8 |
Huawei Kunpeng 920 | 3449.7 | 655.5 |
Intel® Xeon® Gold 6148 CPU @ 2.40GHz | 3395.3 | 1193.4 |
Loongson-3A4000 整型:
========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: loongson-PC: GNU/Linux
OS: GNU/Linux -- 4.19.0-loongson-3-server -- #1187 SMP PREEMPT Wed Mar 25 22:36:49 CST 2020
Machine: mips64 (unknown)
Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
CPU 0: ICT Loongson-3A R4 (Loongson-3A4000) @ 1800MHz (3577.8 bogomips)
CPU 1: ICT Loongson-3A R4 (Loongson-3A4000) @ 1800MHz (3594.0 bogomips)
08:57:43 up 7 days, 21:12, 2 users, load average: 0.00, 0.44, 0.62; runlevel 2020-12-22
------------------------------------------------------------------------
Benchmark Run: 三 12月 30 2020 08:57:43 - 08:59:56
2 CPUs in system; running 1 parallel copy of tests
Dhrystone 2 using register variables 12840354.6 lps (10.0 s, 7 samples)
System Benchmarks Partial Index BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 12840354.6 1100.3
========
System Benchmarks Index Score (Partial Only) 1100.3
Loongson-3A4000 浮点:
========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: loongson-PC: GNU/Linux
OS: GNU/Linux -- 4.19.0-loongson-3-server -- #1187 SMP PREEMPT Wed Mar 25 22:36:49 CST 2020
Machine: mips64 (unknown)
Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
CPU 0: ICT Loongson-3A R4 (Loongson-3A4000) @ 1800MHz (3577.8 bogomips)
CPU 1: ICT Loongson-3A R4 (Loongson-3A4000) @ 1800MHz (3594.0 bogomips)
09:03:57 up 7 days, 21:18, 2 users, load average: 0.14, 0.27, 0.50; runlevel 2020-12-22
------------------------------------------------------------------------
Benchmark Run: 三 12月 30 2020 09:03:57 - 09:06:22
2 CPUs in system; running 1 parallel copy of tests
Double-Precision Whetstone 2077.9 MWIPS (9.9 s, 7 samples)
System Benchmarks Partial Index BASELINE RESULT INDEX
Double-Precision Whetstone 55.0 2077.9 377.8
========
System Benchmarks Index Score (Partial Only) 377.8
Huawei Kunpeng 920 整型:
========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: ecs-kc1-large-2-linux-20201025105424: GNU/Linux
OS: GNU/Linux -- 4.15.0-124-generic -- #127-Ubuntu SMP Fri Nov 6 10:58:37 UTC 2020
Machine: aarch64 (aarch64)
Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
CPU 0: (200.0 bogomips)
CPU 1: (200.0 bogomips)
08:57:13 up 16 days, 14:14, 1 user, load average: 0.00, 0.00, 0.00; runlevel 2020-12-13
------------------------------------------------------------------------
Benchmark Run: Wed Dec 30 2020 08:57:13 - 08:59:23
2 CPUs in system; running 1 parallel copy of tests
Dhrystone 2 using register variables 40257567.5 lps (10.0 s, 7 samples)
System Benchmarks Partial Index BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 40257567.5 3449.7
========
System Benchmarks Index Score (Partial Only) 3449.7
Huawei Kunpeng 920 浮点:
========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: ecs-kc1-large-2-linux-20201025105424: GNU/Linux
OS: GNU/Linux -- 4.15.0-124-generic -- #127-Ubuntu SMP Fri Nov 6 10:58:37 UTC 2020
Machine: aarch64 (aarch64)
Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
CPU 0: (200.0 bogomips)
CPU 1: (200.0 bogomips)
09:03:48 up 16 days, 14:21, 1 user, load average: 0.01, 0.11, 0.07; runlevel 2020-12-13
------------------------------------------------------------------------
Benchmark Run: Wed Dec 30 2020 09:03:48 - 09:06:28
2 CPUs in system; running 1 parallel copy of tests
Double-Precision Whetstone 3605.4 MWIPS (9.8 s, 7 samples)
System Benchmarks Partial Index BASELINE RESULT INDEX
Double-Precision Whetstone 55.0 3605.4 655.5
========
System Benchmarks Index Score (Partial Only) 655.5
Intel® Xeon® Gold 6148 CPU @ 2.40GHz 整型:
========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: VM-0-16-ubuntu: GNU/Linux
OS: GNU/Linux -- 5.4.0-42-generic -- #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
Machine: x86_64 (x86_64)
Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
CPU 0: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (4800.0 bogomips)
x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
09:00:07 up 2 days, 16:00, 1 user, load average: 0.32, 0.24, 0.10; runlevel 2020-12-27
------------------------------------------------------------------------
Benchmark Run: Wed Dec 30 2020 09:00:07 - 09:02:17
1 CPU in system; running 1 parallel copy of tests
Dhrystone 2 using register variables 39623549.0 lps (10.0 s, 7 samples)
System Benchmarks Partial Index BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 39623549.0 3395.3
========
System Benchmarks Index Score (Partial Only) 3395.3
Intel® Xeon® Gold 6148 CPU @ 2.40GHz 整型:
========================================================================
BYTE UNIX Benchmarks (Version 5.1.3)
System: VM-0-16-ubuntu: GNU/Linux
OS: GNU/Linux -- 5.4.0-42-generic -- #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
Machine: x86_64 (x86_64)
Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8")
CPU 0: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (4800.0 bogomips)
x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET
09:03:44 up 2 days, 16:03, 1 user, load average: 0.17, 0.32, 0.17; runlevel 2020-12-27
------------------------------------------------------------------------
Benchmark Run: Wed Dec 30 2020 09:03:44 - 09:06:17
1 CPU in system; running 1 parallel copy of tests
Double-Precision Whetstone 6563.8 MWIPS (9.8 s, 7 samples)
System Benchmarks Partial Index BASELINE RESULT INDEX
Double-Precision Whetstone 55.0 6563.8 1193.4
========
System Benchmarks Index Score (Partial Only) 1193.4