概述
mongodb 是一个流行的面向文档的,跨平台开源 nosql 数据库。其灵活的数据模型能支持存储具有完整索引支持和复制的非结构化数据。根据 db-engines 的数据,截至 2023 年 1 月,mongodb 是第五大最受欢迎的数据库。它是用 c++ 编写的,旨在为 web 应用程序提供可扩展的高性能数据存储解决方案。
本指南的目的是描述在 ampere altra 处理器上以最佳方式运行 mongodb 的一些技术参考。
01构建先决条件
以高性能方式运行应用程序首先要正确构建应用程序并使用适当的编译器标志。当在 ampere altra 处理器上从源码开始构建并运行应用程序时,我们建议使用 gcc 编译器版本 10 或更高的版本。较新版本的编译器往往对新的处理器特性有更好的支持,并结合了更高级的代码生成技术。
我们的测试使用 centos stream 8 作为操作系统。
从 scl 存储库下载并安装了 gcc 11:
yum -y install scl-utils scl-utils-build yum -y install gcc-toolset-11.aarch64 scl enable gcc-toolset-11 bash
对于 ubuntu 22.04 lts 和 debian 等其他操作系统,gcc 11 也是可用的,可以直接从各自的存储库安装。
02构建和安装
mongodb 可以从操作系统包管理器提供的存储库中安装,也可以直接从源代码构建。全面的 mongodb 安装指南可以在官方文档中找到。我们建议从源代码安装,以获得更好的灵活性,以及控制和配置特定模块的能力。
为了构建针对 ampere altra 处理器家族优化的 mongodb,可以在编译阶段添加可以利用硬件特性的额外编译选项。用于编译的 mongodb 源代码可以从 mongodb 下载页面获得。本指南使用稳定版本 mongodb 6.0.3。从源代码安装需要某些库和附加模块,它们将被编译成二进制文件。
mongodb 安装指南:https://github.com/mongodb/mongo/blob/master/docs/building.md
mongodb 下载页面:
https://github.com/mongodb/mongo
执行以下步骤来安装依赖项。
yum -y install libcurl-devel python39 python39-devel openssl-develyum -y install zlib-devel git wget xz-develyum -y groupinstall development tools
要支持 https 连接,请从各自的 git 存储库下载这些附加源代码的最新代码。
git clone [https://github.com/mongodb/mongo](https://github.com/mongodb/mongo)git checkout -b myr6.0.3.rc2 r6.0.3-rc2
需要 python 3.7+,并且必须安装几个 python 模块,运行命令:
python3 -m pip install -r etc/pip/compile-requirements.txt
编译
diff a/src/mongo/db/stats/counters.h b/src/mongo/db/stats/counters.h224a225,226> static_assert(sizeof(decltype(_together)) cache line spill);
python3 buildscripts/scons.py 支持许多编译选项,如 cc, cflags 等。
# get help of scons, such as define cxx=, cc= python3 buildscripts/scons.py -h# note: configure g++ and gcc path# --force-jobs is cpu core numberpython3 buildscripts/scons.py --force-jobs=8040 destdir=
mongodb 配置
在本指南中,mongodb 被配置为使用 wiredtiger 存储引擎和 snappy 作为块和日志压缩器。请参考附录中显示的 mongodb.conf 文件配置服务器。
#start the server$mongodb_install_dir/bin/mongod --config mongod_conf --storageengine wiredtiger#stop the server$mongodb_install_dir/bin --config mongod_conf --shutdown
03性能优化
有数百种设置可以改变 mongodb 的功能和性能。下面列出的只是一些可以使用的更常见的调节变量。推荐参考 mongodb 文档了解所有设置详情。
cachesizegb
定义了内部使用的缓存最大值,wiredtiger 将其适用于所有数据。
增加 cachesizegb 可以减少磁盘 io 的影响,提高读写性能。
使用“db.serverstatus(). wiredtiger”命令检查“maximum bytes configured”(cachesizegb或默认设置配置的最大缓存大小)和“bytes current in the cache”(当前缓存中的数据大小)。
eviction 优化
当应用程序接近最大缓存大小时,wiredtiger 开始清除,以防止内存使用增长过大,遵循“最近最少使用”算法。 eviction=(threads_min=x) 是正在运行的 wiredtiger eviction 工作线程的最小数量,取值必须在 1 到 20 之间。
eviction=(threads_max=x) 是正在运行的wiredtiger eviction工作线程的最大数量。取值必须在 1 到 20 之间。这应该与 mongodb 的 threads_min 设置相匹配。
#getdb.admincommand({getparameter: 1, wiredtigerengineruntimeconfig: eviction}){ wiredtigerengineruntimeconfig: 'eviction=(threads_min=4,threads_max=8)', ok: 1}#setdb.admincommand({setparameter: 1, wiredtigerengineruntimeconfig: eviction=(threads_min=4,threads_max=8)})
concurrenttransactions
iredtiger 使用 ticket 来控制存储引擎同时处理的读/写操作的数量。默认值是 128,在大多数情况下都很有效的。如果 ticket 降为 0,则后续所有操作都排队等待新的 ticket。长时间运行的操作可能会导致可用 ticket 的数量减少,从而降低系统的并发性。例如,增加 ticket 的配置值可以增加并发性。
#读取当前值db.serverstatus().wiredtiger.concurrenttransactions{ write: { out: 0, available: 128, totaltickets: 128 }, read: { out: 0, available: 128, totaltickets: 128 }}#修改值db.admincommand({setparameter: 1, wiredtigerconcurrentwritetransactions: 256}){ was: 0, ok: 1 }db.admincommand({setparameter: 1, wiredtigerconcurrentreadtransactions: 256}){ was: 0, ok: 1 }
journalcompressor
指定用于压缩 wiredtiger 日志数据的压缩类型。压缩操作会消耗额外的 cpu 资源,但也最小化了存储消耗。
blockcompressor
指定集合数据的默认压缩。在创建集合时,可以在每个集合的基础上重置此设置。当然压缩操作会消耗额外的 cpu 资源,但也最小化了存储消耗。
64k pagesize
内核 pagesize 建议设置为 64k。可以使用命令“getconf pagesize”来确定。pagesize 是一个内存页的大小,以字节为单位,在编译内核时配置。使用较大的页面可以减少将虚拟页面地址转换为物理页面地址的硬件延迟。延迟的减少是由于硬件翻译缓存(如 translation lookaside buffer,tlb)的效率得到了提高。因为硬件转换缓存只有有限数量的条目,所以使用更大的页面大小会增加缓存中每个条目可以转换的虚拟内存量。这不但增加了应用程序可以访问的内存量,而且不会导致硬件转换延迟。
transparent huge pages
透明大页(transparent huge pages, thp)是一种 linux 内存管理系统,它通过使用更大的内存页,减少了在具有大量内存的机器上 tlb(translation lookaside buffer)查找的开销。然而,在启用 thp 的情况下,数据库工作负载通常表现不佳,因为它们往往具有稀疏而非连续的内存访问模式。在 linux 上运行 mongodb 时,应该禁用 thp 以获得最佳性能。
echo never > /sys/kernel/mm/transparent_hugepage/enabled
大多数类 unix 操作系统,包括 linux 和 macos,都提供了在每个进程和每个用户的基础上限制和控制系统资源(如线程、文件和网络连接)使用的方法。这些“限制”可以防止单个用户使用过多的系统资源。有时,这些限制的默认值比较低,这可能会在正常的 mongodb 操作过程中导致许多问题。
要为这些版本配置 ulimit 值,请创建一个名为 /etc/security/limits.d/99-mongodb-nproc.conf 的文件,并添加新值以提高该进程的限制阈值。
echo * soft fsize unlimited | sudo tee -a /etc/security/limits.confecho * hard fsize unlimited | sudo tee -a /etc/security/limits.confecho * soft cpu unlimited | sudo tee -a /etc/security/limits.confecho * hard cpu unlimited | sudo tee -a /etc/security/limits.confecho * soft as unlimited | sudo tee -a /etc/security/limits.confecho * hard as unlimited | sudo tee -a /etc/security/limits.confecho * soft memlock unlimited | sudo tee -a /etc/security/limits.confecho * hard memlock unlimited | sudo tee -a /etc/security/limits.confecho * soft nofile 64000 | sudo tee -a /etc/security/limits.confecho * hard nofile 64000 | sudo tee -a /etc/security/limits.confecho * soft nproc 64000 | sudo tee -a /etc/security/limits.confecho * hard nproc 64000 | sudo tee -a /etc/security/limits.conf
为您的部署配置足够的文件句柄(fs.file-max)、内核 pid 限制(kernel.pid_max)、每个进程的最大线程数(kernel.threads-max)和每个进程的最大内存映射区域数(vm.max_map_count)。对于大型系统,以下值是不错的参考值:
sysctl -w vm.max_map_count = 98000sysctl -w kernel.pid_max = 64000sysctl -w kernel.threads-max = 64000sysctl -w vm.max_map_count=128000sysctl -w net.core.somaxconn=65535
开始调优并使用吞吐量-性能配置文件
tuned-adm profile throughput-performance
04附录
mongodb conf file
processmanagement: fork: truenet: bindip: %server% port: %port%storage: dbpath: %data_root%/%port% engine: wiredtiger wiredtiger: engineconfig: journalcompressor: snappy cachesizegb: 30 collectionconfig: blockcompressor: snappysystemlog: destination: file path: %data_root%/%port%/mongod.log logappend: truestorage: journal: enabled: true
伺服电机和伺服驱动器区别
旁路电容、去耦电容及滤波电容的作用详解
创世界纪录 中国10比特光量子计算机诞生
中国移动咪咕联合央视新闻利用5G技术完成了阅兵高清直播
官方iPhone 11系列保护壳曝光,得知命名以及外观设计
针对Ampere Altra处理器的MongoDB优化指南
Opera优化底层代码,提速16%
如何利用物联网技术来追踪药品
安富利帮助初创企业完成无人车设计和开发
SMT工艺问题分析
工控主板启动时无法显示,原因有哪些
华为已经在威尔士进行了Open RAN技术测试?
第三方支付平台推荐度排行榜:支付宝连续7年第一
核芯互联双通道16b/260MSPS ADC CL3669简析
手机恶意软件是怎么样入侵的需要注意什么
智慧城市:发展成为公民友好和可持续发展的城市
PLC对4个伺服电动缸进行控制的方法
众泰T600尊贵型上手体验评测
华米宣布黄山1号量产 号称全球智能穿戴领域第一颗人工智能芯片
德国大众联合度普加入充电桩“布局战”