我正在尝试理解 mongodb 读取语义。根据文档,除非您更改读取首选项,否则它始终是副本集中的主服务器。
我的设置:Linux VM:4GB RAM,1 个核心,在同一个 VM 上运行 3 个 mongo 实例(我知道这是一个糟糕的设置!但这就是我现在从 ops 获得的方式)
当我从 Java 驱动程序运行以下 mongo 查询时,我只是在监视内存使用情况、日志等。
这是我看到的:
ReadPreference.PrimaryPreferred:
最佳
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17874(primary) mongod 20 0 43.0g 1.3g 1.1g S 14.3 36.0 109:06.71 mongod
18048(secondary-1) mongod 20 0 42.7g 690m 88m S 0.3 18.0 28:45.09 mongod
18207(secondary-2) mongod 20 0 42.7g 641m 60m S 0.3 16.7 28:53.13 mongod
日志
小学一
Fri Aug 2 21:35:39.416 [initandlisten] connection accepted from 10.10.1.57:54306 #11927 (40 connections now open)
Fri Aug 2 21:44:16.332 [initandlisten] connection accepted from 10.10.1.57:54376 #11963 (41 connections now open)
Fri Aug 2 21:44:16.348 [initandlisten] connection accepted from 10.10.1.57:54377 #11964 (42 connections now open)
Fri Aug 2 21:44:16.414 [initandlisten] connection accepted from 10.10.1.57:54380 #11965 (43 connections now open)
中学一
Fri Aug 2 20:03:43.066 [conn11270] end connection 10.10.1.57:53547 (20 connections now open)
Fri Aug 2 20:03:43.066 [conn11271] end connection 10.10.1.57:53551 (19 connections now open)
Fri Aug 2 21:44:16.331 [initandlisten] connection accepted from 10.10.1.57:54374 #11776 (19 connections now open)
Fri Aug 2 21:44:16.350 [initandlisten] connection accepted from 10.10.1.57:54378 #11777 (20 connections now open)
中学二
Fri Aug 2 20:03:43.065 [conn11271] end connection 10.10.1.57:53552 (20 connections now open)
Fri Aug 2 20:03:43.066 [conn11270] end connection 10.10.1.57:53549 (19 connections now open)
Fri Aug 2 21:44:16.331 [initandlisten] connection accepted from 10.10.1.57:54375 #11776 (19 connections now open)
Fri Aug 2 21:44:16.352 [initandlisten] connection accepted from 10.10.1.57:54379 #11777 (20 connections now open)
ReadPreference.Secondary:
最佳
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18048(secondary-1) mongod 20 0 42.7g 1.1g 517m S 7.3 29.2 29:28.00 mongod
17874(primary) mongod 20 0 43.0g 1.0g 777m S 0.3 26.7 112:57.05 mongod
18207(secondary-2) mongod 20 0 42.7g 617m 37m S 0.3 16.1 28:59.08 mongod
日志
==> mongod_rs0-0.log <==
Fri Aug 2 22:19:01.056 [conn12118] end connection 10.10.10.201:52558 (34 connections now open)
Fri Aug 2 22:19:01.057 [initandlisten] connection accepted from 10.10.10.201:52564 #12120 (35 connections now open)
==> mongod_rs0-1.log <==
Fri Aug 2 22:19:04.038 [conn11925] end connection 10.10.10.201:46443 (15 connections now open)
Fri Aug 2 22:19:04.039 [initandlisten] connection accepted from 10.10.10.201:46449 #11927 (16 connections now open)
==> mongod_rs0-2.log <==
Fri Aug 2 22:19:04.050 [conn11925] end connection 10.10.10.201:37641 (14 connections now open)
Fri Aug 2 22:19:04.050 [initandlisten] connection accepted from 10.10.10.201:37647 #11927 (15 connections now open)
我的问题是:
- 在这两种情况下,CPU 使用率都反映了您的阅读偏好,但我不太了解日志。为什么在我查询时它会在每个实例上打开连接?
- 为什么primary保持更多no。即使 readpreference 是 SecondaryPreferred 的连接数。
- 每个实例上的 tcpdump 都处于活动状态。其中2个应该是空闲的,对吧?没有其他客户端/进程调用此集群。