成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

mongo監(jiān)控及性能調(diào)優(yōu)

fsmStudy / 3240人閱讀

摘要:命令行方式獲取顯示當(dāng)前的用戶操作。類似于的可以監(jiān)控所有慢的以及不慢的查詢。以及其他第三方鏈接性能調(diào)優(yōu)場景現(xiàn)實的首頁我們希望現(xiàn)實最近發(fā)布的條。自動刪除舊文檔為了給新文檔創(chuàng)建空間,在集合中自動刪除老舊的文檔,不需要執(zhí)行額外的腳本和操作。

轉(zhuǎn)載請注明出處 http://www.paraller.com
原文排版地址 http://www.paraller.com/2016/10/22/mongo%E7%9B%91%E6%8E%A7%E5%8F%8A%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98/

監(jiān)控策略

mongo監(jiān)控的策略主要有以下兩種:

一系列的工具能夠報告實時信息

數(shù)據(jù)庫命令能夠返回當(dāng)前數(shù)據(jù)庫的詳細(xì)精確信息

mongostat

mongostat captures and returns the counts of database operations by type (e.g. insert, query, update, delete, etc.). These counts report on the load distribution on the server.

Use mongostat to understand the distribution of operation types and to inform capacity planning. See the mongostat manual for details.

root@db94dfee43b5:/# mongostat 
insert query update delete getmore command dirty used flushes vsize   res qrw arw net_in net_out conn                time
    *0    *0     *0     *0       0     2|0  0.0% 0.1%       0  270M 59.0M 0|0 0|0   160b   45.5k    2 Aug 29 08:48:07.749
    *0    *0     *0     *0       0     1|0  0.0% 0.1%       0  270M 59.0M 0|0 0|0   157b   44.8k    2 Aug 29 08:48:08.749

每個字段代表的意思

inserts
The number of objects inserted into the database per second. If followed by an asterisk (e.g. *), the datum refers to a replicated operation.

query
The number of query operations per second.

update
The number of update operations per second.

delete
The number of delete operations per second.

getmore
The number of get more (i.e. cursor batch) operations per second.

command
The number of commands per second. On slave and secondary systems, mongostat presents two values separated by a pipe character (e.g. |), in the form of local|replicated commands.

flushes
Changed in version 3.0.

For the WiredTiger Storage Engine, flushes refers to the number of WiredTiger checkpoints triggered between each polling interval.
For the MMAPv1 Storage Engine, flushes represents the number of fsync operations per second.

dirty
New in version 3.0.

Only for WiredTiger Storage Engine. The percentage of the WiredTiger cache with dirty bytes, calculated by wiredTiger.cache.tracked dirty bytes in the cache / wiredTiger.cache.maximum bytes configured.

used
New in version 3.0.

Only for WiredTiger Storage Engine. The percentage of the WiredTiger cache that is in use, calculated by wiredTiger.cache.bytes currently in the cache / wiredTiger.cache.maximum bytes configured.

mapped
Changed in version 3.0.

Only for MMAPv1 Storage Engine. The total amount of data mapped in megabytes. This is the total data size at the time of the last mongostat call.

vsize
The amount of virtual memory in megabytes used by the process at the time of the last mongostat call.

res
The amount of resident memory in megabytes used by the process at the time of the last mongostat call.

faults
Changed in version 3.0.

Only for MMAPv1 Storage Engine. The number of page faults per second.
Changed in version 2.1: Before version 2.1, this value was only provided for MongoDB instances running on Linux hosts.

lr
New in version 3.2.

Only for MMAPv1 Storage Engine. The percentage of read lock acquisitions that had to wait. mongostat displays lr|lw if a lock acquisition waited.

lw
New in version 3.2.

Only for MMAPv1 Storage Engine. The percentage of write lock acquisitions that had to wait. mongostat displays lr|lw if a lock acquisition waited.

locked
Changed in version 3.0: Only appears when mongostat runs against pre-3.0 versions of MongoDB instances.

The percent of time in a global write lock.

idx miss
Changed in version 3.0.

Only for MMAPv1 Storage Engine. The percent of index access attempts that required a page fault to load a btree node. This is a sampled value.

qr
The length of the queue of clients waiting to read data from the MongoDB instance.

qw
The length of the queue of clients waiting to write data from the MongoDB instance.

ar
The number of active clients performing read operations.

aw
The number of active clients performing write operations.

netIn
The amount of network traffic, in bytes, received by the MongoDB instance.

This includes traffic from mongostat itself.

conn
The total number of open connections.

set
The name, if applicable, of the replica set.

Add Fields to mongostat Output

root@db94dfee43b5:/# mongostat -O "host,version,network.numRequests=network requests"
insert query update delete getmore command dirty used flushes vsize   res qrw arw net_in net_out conn                time            host version network requests
    *0    *0     *0     *0       0     2|0  0.0% 0.1%       0  271M 59.0M 0|0 0|0   158b   44.8k    2 Aug 29 09:45:11.850 localhost:27017   3.4.2             6319
    *0    *0     *0     *0       0     2|0  0.0% 0.1%       0  271M 59.0M 0|0 0|0   158b   44.9k    2 Aug 29 09:45:12.847 localhost:27017   3.4.2             6323
    *0    *0     *0     *0       0     1|0  0.0% 0.1%       0  271M 59.0M 0|0 0|0   157b   44.7k    2 Aug 29 09:45:13.849 localhost:27017   3.4.2             6327
    *0    *0     *0     *0       0     1|0  0.0% 0.1%       0  271M 59.0M 0|0 0|0   157b   44.7k    2 Aug 29 09:45:14.850 localhost:27017   3.4.2             6331
mongotop

racks and reports the current read and write activity of a MongoDB instance, and reports these statistics on a per collection basis.

Http Console
mongo:
  image: mongo:latest
  volumes:
    - /Users/zhidaliao/bak_dir/mongo:/data/db
  ports:
    - "27017:27017"
    - "1000:1000"
    - "28017:28017"
  command: ["mongod", "--rest"]

--httpinterface 還可以增加參數(shù)進行接口操作

在瀏覽器中訪問 http://localhost:28017/ 可以查看實時信息,不推薦在生產(chǎn)環(huán)境中使用,安全性和穩(wěn)定性。

命令行方式獲取 db.currentOp()

顯示當(dāng)前的用戶操作。

db.serverStatus()

詳細(xì)的Mongo服務(wù)器信息。主要關(guān)注的點

connections 當(dāng)前連接和可用連接數(shù),聽過一個同行介紹過,mongodb最大處理到2000個連接就不行了(要根據(jù)你的機器性能和業(yè)務(wù)來設(shè)定),所以設(shè)大了沒意義。設(shè)個合理值的話,到達這個值mongodb就拒絕新的連接請求,避免被太多的連接拖垮。

indexCounters:btree:misses 索引的不命中數(shù),和hits的比例高就要考慮索引是否正確建立。你看我的”missRatio” : 3.543930204420982e-7,很健康吧。所以miss率在mongostat里面也可以看

db.stats()
> db.stats()
{
    "db" : "yea",
    "collections" : 31,
    "views" : 0,
    "objects" : 45827,
    "avgObjSize" : 345.1348768193423,
    "dataSize" : 15816496,
    "storageSize" : 7372800,
    "numExtents" : 0,
    "indexes" : 54,
    "indexSize" : 2985984,
    "ok" : 1
}
db.collection.stats()

mongo數(shù)據(jù)庫的集合詳細(xì)信息。

replSetGetStatus

The replSetGetStatus command (rs.status() from the shell) returns an overview of your replica set’s status.

profiler

類似于MySQL的slow log, MongoDB可以監(jiān)控所有慢的以及不慢的查詢。
Profiler默認(rèn)是關(guān)閉的,你可以選擇全部開啟,或者有慢查詢的時候開啟。

> use test
switched to db test
> db.setProfilingLevel(2);
{"was" : 0 , "slowms" : 100, "ok" : 1} 
> db.getProfilingLevel()
2

slowms:代表輸出 操作大于100毫秒的語句

To change the threshold, pass two parameters to the db.setProfilingLevel() helper in the mongo shell. The first parameter sets the profiling level for the current database, and the second sets the default slow operation threshold for the entire mongod instance.

設(shè)置0代表當(dāng)前的數(shù)據(jù)庫禁止profiler功能,但是這個Mongo實例下的數(shù)據(jù)庫,只要等級是1的,都會使用20ms的配置

db.setProfilingLevel(0,20)

查看Profile日志

> db.system.profile.find().sort({$natural:-1})
{"ts" : "Thu Jan 29 2009 15:19:32 GMT-0500 (EST)" , "info" :
"query test.$cmd ntoreturn:1 reslen:66 nscanned:0 query: { profile: 2 } nreturned:1 bytes:50" ,
"millis" : 0} ...

3個字段的意義

ts:時間戳

info:具體的操作

millis:操作所花時間,毫秒

Database Profiler?

第三方監(jiān)測工具

MongoDB Monitoring Service : MongoDB Monitoring Service(MMS)是Mongodb廠商提供的監(jiān)控服務(wù),可以在網(wǎng)頁和Android客戶端上監(jiān)控你的MongoDB狀況。

以及其他第三方鏈接:
Third Party Tools

性能調(diào)優(yōu)

場景:現(xiàn)實blog的首頁-我們希望現(xiàn)實最近發(fā)布的10條posts。ts為時間字段。

db.posts.find().sort({ts:-1}); 
創(chuàng)建索引
db.posts.ensureIndex({ts:1});

數(shù)據(jù)庫就可以基于索引信息排序,不會直接查看每個document

限定結(jié)果

MongoDB游標(biāo)返回一組document,我們叫這個為chunks.

articles = db.posts.find().sort({ts:-1}).limit(10); 
查詢特定的字段
db.oauth_clients.find({},{clientId:1,clientSecret:1})

如果你選擇了要查詢的字段,那么返回的就是部分對象。這個對象并不能直接進行更新

讀寫分離

如果讀寫都在主節(jié)點的話,從節(jié)點就一直處在空置狀態(tài),這是一種浪費。對于報表或者搜索這種讀操作來說完全可以在從節(jié)點實現(xiàn),因此要做的是在 connection string 中設(shè)置成 secondarypreferred。

Capped Collections

Capped Collections?

Capped collections 是固定大小的集合,基于插入的順序,支持高速的讀寫文檔的操作, Capped collections 工作機制于循環(huán)緩存類似: 一旦一個集合填充了他被分配的空間,對于新插入的文檔他會覆蓋舊文檔的空間

表現(xiàn)形式
Insertion Order

Capped collections 保證插入順序.所以查詢的時候不需要根據(jù)索引返回結(jié)果,而是通過插入順序返回,沒有索引, capped collections 可以支持高速插入操作,類似于數(shù)據(jù)庫。

自動刪除舊文檔

為了給新文檔創(chuàng)建空間, capped collections 在集合中自動刪除老舊的文檔,不需要執(zhí)行額外的腳本和操作。

舉個例子,oplog.rs collection 在副本形式下保存的操作日志就是使用capped collection。以下的潛在的場景:

在高速系統(tǒng)中儲存日志,或者在隊列形式的事件機制中保持順序。

capped collections緩存少量的數(shù)據(jù),因為緩存的讀操作別寫操作更頻繁,你可以確保你的集合總是保存在你的工作區(qū)(比如內(nèi)存),或者你能接受一些需要保持順序的寫操作。

_id Index

Capped collections have an _id field and an index on the _id field by default.

優(yōu)缺點
Updates

如果你準(zhǔn)備更新文檔,創(chuàng)建了索引所以這些更新操作不需要 經(jīng)過集合掃描。

Document Size

Changed in version 3.2.

文檔大小是固定的,如果 更新和替換操作,改變了文檔大小,操作將會失敗

Document Deletion

你不能刪除文檔,只能使用drop()方法刪掉集合并重新創(chuàng)建新的內(nèi)容。

Sharding 分片

capped collection 不支持分片操作

Query Efficiency

使用自然的排序去獲取最近插入集合的元素是更有效率的,類似誒于在日志文件中tail 的命令

函數(shù) $out

$out 管道操作對capped collection無效

程序操作
Create a Capped Collection 創(chuàng)建

db.createCollection()命令創(chuàng)建,但是要指定參數(shù)預(yù)分配空間,單位字節(jié)。

db.createCollection( "log", { capped: true, size: 100000 } )

如果空間小于或者等于4096, 集合將會劃分出 4096 bytes. MongoDB規(guī)劃的大小以256的倍數(shù)字節(jié)擴增

另外,我們可以指定max參數(shù),用來限制最大的文檔數(shù)量(不是集合的空間大小,而是數(shù)量)

db.createCollection("log", { capped : true, size : 5242880, max : 5000 } )
Query a Capped Collection 查詢

當(dāng)你使用find函數(shù)沒有指定排序的時候,mongodb會保證按照插入順序返回。如果要按照插入順序的逆序返回結(jié)果,find()函數(shù) 要緊接著 sort()函數(shù),使用natural參數(shù)指定為-1

db.cappedCollection.find().sort( { $natural: -1 } )

檢查是否是Capped 集合

db.collection.isCapped()

Convert a Collection to Capped ,普通集合轉(zhuǎn)換成 Capped類型

db.runCommand({"convertToCapped": "mycoll", size: 100000});

This command obtains a global write lock and will block other operations until it has completed.

TTL

Setting TTL. These indexes allow you to expire and remove data from normal collections using a special type, based on the value of a date-typed field and a TTL value for the index.
TTL Collections are not compatible with capped collections.

Tailable Cursor

You can use a tailable cursor with capped collections. Similar to the Unix tail -f command, the tailable cursor “tails” the end of a capped collection. As new documents are inserted into the capped collection, you can use the tailable cursor to continue retrieving documents.

IMPORTANT
size參數(shù)總是必須的,即使你指定了max數(shù)量,mongoDb會移除更舊的文檔,如果你的集合到達了指定的最大空間限制,在最大的條數(shù)限制條數(shù)之前。

參考網(wǎng)站

MongoDB 優(yōu)化

Monitoring for MongoDB?

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/19119.html

相關(guān)文章

  • PHP 性能分析第一篇: Xhprof & Xhgui 介紹

    摘要:注這是我們應(yīng)用性能分析系列的第一篇,閱讀第二篇可深入了解,第三篇則關(guān)注于性能調(diào)優(yōu)實踐。性能分析的行為也會影響應(yīng)用性能。主動被動性能分析主動分析器在開發(fā)過程中使用,由開發(fā)人員啟用。它對性能的影響最小,同時收集足夠的信息用于診斷性能問題。 注:這是我們 PHP 應(yīng)用性能分析系列的第一篇,閱讀第二篇可深入了解 xhgui,第三篇則關(guān)注于性能調(diào)優(yōu)實踐。 什么是性能分析? 性能分析是衡量應(yīng)用程...

    RdouTyping 評論0 收藏0
  • 性能測試

    摘要:吞吐量一般結(jié)合業(yè)務(wù)需求而定服務(wù)器資源占用占用率內(nèi)存使用率命中率篇是一種預(yù)測系統(tǒng)行為和性能的負(fù)載測試工具。負(fù)載測試與壓力測試都是性能測試。通過平臺接口可進行合理的性能測試。有利于測試人員及時定位問題。 Part 1:性能測試 性能測試是通過自動化的測試工具模擬多種正常、峰值以及異常負(fù)載條件來對系統(tǒng)的各項性能指標(biāo)進行測試。 A. 類別 性能測試包括負(fù)載測試、壓力測試、基準(zhǔn)測試等。 i. 負(fù)...

    qpal 評論0 收藏0
  • Docker的LNMP一鍵安裝開發(fā)環(huán)境 + PHP非侵入式監(jiān)控平臺xhgui(優(yōu)化系統(tǒng)性能、定位Bu

    摘要:的一鍵安裝開發(fā)環(huán)境非侵入式監(jiān)控平臺優(yōu)化系統(tǒng)性能定位的神器之前在用做本地開發(fā)環(huán)境,因為沒有這些對程序性能追蹤及分析的工具,所以索性基于的編排了一套自己使用。 DNMP PLUS dnmp = Docker + Nginx + MySQL + PHP + Redis + MongDB plus = xhgui + xhprof + tideways dnmp-plus = PHPer 的一...

    AlanKeene 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<