Author: Ren Zhongyu
As a member of aikesheng DBA team, he is good at fault analysis and performance optimization. Please discuss relevant technical issues in this article.
Source: original contribution
*It is produced by aikesheng open source community. The original content cannot be used without authorization. For reprint, please contact Xiaobian and indicate the source.
In July last year, MongoDB Inc sent us MongoDB 5.0. This version not only brings the core feature - timing set, but also buries some small "pits" if it is used carelessly; If your environment is preparing to install, try or upgrade to MongoDB 5.0, you may wish to discuss it later.
phenomenon
First note that my Linux version is CentOS Linux release 7.2.1511.
Install the latest mongodb-5.0 After X, execute mongo or mongod and directly report the error legal instruction.
[root@10-186-61-38 mongodb]# cd mongodb-linux-x86_64-rhel70-5.0.5/bin/ [root@10-186-61-38 bin]# ./mongo --help Illegal instruction [root@10-186-61-38 bin]# ./mongod --help Illegal instruction
Full of doubts, there is no problem using the lower version of MongoDB 4.4.9.
[root@10-186-61-38 mongodb]# cd mongodb-linux-x86_64-rhel70-4.4.9/bin/ [root@10-186-61-38 bin]# ./mongo --help MongoDB shell version v4.4.9 usage: ./mongo [options] [db address] [file names (ending in .js)]
Check
Execute the mongo or mongod command to obtain 2 lines of demsg logs with errors:
[root@10-186-61-38 bin]# dmesg -T ······ [Thu Dec 23 18:05:13 2021] traps: mongo[16596] trap invalid opcode ip:7f0ad9fa90da sp:7ffe9deaa050 error:0 in mongo[7f0ad7f86000+2c8c000] [Thu Dec 23 18:05:17 2021] traps: mongod[16597] trap invalid opcode ip:7f3b1e329a6a sp:7ffc8fb540e0 error:0 in mongod[7f3b1a355000+5110000]
It can be seen that the command execution failure is caused by invalid opcode, which seems to be related to some instruction set of the operating system.
Search MongoDB community with doubts and keywords and find similar error reports:
Although the operating system of this case is Ubuntu, the system error message is similar. The reason for the error is that the basic requirement of mongodb version 5.0 is that the CPU of the server needs to support AVX instruction set.
After carefully searching the official documents, you can see that the installation of mongodb version 5.0 really depends on the CPU supporting AVX instruction set:
For CPU models that currently support AVX instruction set, please refer to the link:
https://en.wikipedia.org/wiki...
Check the CPU of my own server. It does not support avx (Note: if avx instruction set is supported, the flag field will print 'avx' string):
[root@10-186-61-38 ~]# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 13 model name : QEMU Virtual CPU version 2.5+ ······ flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pse36 clflush mmx fxsr sse sse2 syscall nx lm rep_good nopl xtopology eagerfpu pni cx16 x2apic hypervisor lahf_lm ······
CPU test supporting AVX
Find a server whose CPU supports AVX instruction set for testing.
The command of MongoDB 5.0 is executed normally.
AVX instruction set
AVX (Advanced Vector Extensions) is the instruction set in x86 microprocessor
- Proposed by Intel in March 2008 and first supported in Sandy Bridge series processors released in the first quarter of 2011. AMD began to support AVX in the Bulldozer series processors released in the third quarter of 2011. Therefore, AVX instruction set may not be supported in older CPU architectures. AVX is the SSE extension architecture of X86 instruction set. Like IA16 to IA32, it improves the register XMM 128bit to YMM 256bit. Therefore, in theory, the operation performance of CPU will be doubled.
At present, the official MongoDB document only states that the installation of MongoDB 5.0 needs to rely on the server CPU to support AVX instruction set, but does not specify the specific reasons for support;
Only one article about MongoDB with AVX "Getting storage engines ready for fast storage devices" was retrieved on the Internet. It was mentioned that the highly optimized memcpy method based on avx can be used to copy data from the memory mapping area to the buffer of another application; It is speculated that the current release of version 5.0 includes the update of WiredTiger storage engine level mentioned in the article (the article mentioned that the read throughput after updating the engine has increased by 63%), and the optimization and update of the underlying storage engine depends on the support of avx.
https://engineering.mongodb.c...
conclusion
If you need to install or upgrade to the new version of MongoDB 5.0, you must ensure whether your server CPU can support AVX instruction set architecture in advance. The check command is as follows:
grep avx /proc/cpuinfo