bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

深入MongoDB內存溢出調優-創新互聯

MongoDB內存溢出錯誤描述

為芙蓉等地區用戶提供了全套網頁設計制作服務,及芙蓉網站建設行業解決方案。主營業務為成都做網站、成都網站建設、成都外貿網站建設、芙蓉網站設計,以傳統方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業、用心的態度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!exception: getMore runner error: Overflow sort stage buffered data  usage of 33638076 bytes exceeds internal limit of 33554432 bytes

MongoDB內存中排序的限制和解決方案

下文引用自:https://docs.mongodb.com/manual/reference/method/cursor.sort/#cursor.sort

When unable to obtain the sort order from an index, MongoDB will sort the results in memory, which requires that the result set being sorted is less than 32 megabytes.

When the sort operation consumes more than 32 megabytes, MongoDB returns an error. To avoid this error, either create an index supporting the sort operation (see Sort and Index Use) or use sort() in conjunction with limit() (see Limit Results).

MongoDB查詢方法的描述和執行順序

下文引用自:https://docs.mongodb.com/manual/tutorial/query-documents/#query-method

Query Method

MongoDB provides the db.collection.find() method to read documents from a collection. The db.collection.find() method returns a cursor to the matching documents.

db.collection.find( <query filter>, <projection> )

For the db.collection.find() method, you can specify the following optional fields:

  • a query filter to specify which documents to return.

  • a query projection to specifies which fields from the matching documents to return. The projection limits the amount of data that MongoDB returns to the client over the network.

You can optionally add a cursor modifier to impose limits, skips, and sort orders. The order of documents returned by a query is not defined unless you specify a sort().

下文引用自:https://docs.mongodb.com/manual/reference/method/db.collection.find/#combine-cursor-methods

Combine Cursor Methods

The following statements chain cursor methods limit() and sort():

db.bios.find().sort( { name: 1 } ).limit( 5 ) db.bios.find().limit( 5 ).sort( { name: 1 } )

The two statements are equivalent; i.e. the order in which you chain the limit() and the sort() methods is not significant. Both statements return the first five documents, as determined by the ascending sort order on ‘name’.

順便來看看SQL Server語句執行順序

《SQL Server 2005技術內幕--查詢》這本書的開篇第一章第一節。書的作者也要讓讀者首先了解語句是怎么樣的一個執行順序。

查詢的邏輯執行順序:

 (1) FROM < left_table>

 (3) < join_type> JOIN < right_table>  (2) ON < join_condition>

 (4) WHERE < where_condition>

 (5) GROUP BY < group_by_list>

 (6) WITH {cube | rollup}

 (7) HAVING < having_condition>

 (8) SELECT (9) DISTINCT (11) < top_specification> < select_list>

 (10) ORDER BY < order_by_list>

 標準的SQL 的解析順序為:

 (1).FROM 子句 組裝來自不同數據源的數據

 (2).WHERE 子句 基于指定的條件對記錄進行篩選

 (3).GROUP BY 子句 將數據劃分為多個分組

 (4).使用聚合函數進行計算

 (5).使用HAVING子句篩選分組

 (6).計算所有的表達式

 (7).使用ORDER BY對結果集進行排序

執行順序:

 1.FROM:對FROM子句中前兩個表執行笛卡爾積生成虛擬表vt1

 2.ON:對vt1表應用ON篩選器只有滿足< join_condition> 為真的行才被插入vt2

 3.OUTER(join):如果指定了 OUTER JOIN保留表(preserved table)中未找到的行將行作為外部行添加到vt2 生成t3如果from包含兩個以上表則對上一個聯結生成的結果表和下一個表重復執行步驟和步驟直接結束

 4.WHERE:對vt3應用 WHERE 篩選器只有使< where_condition> 為true的行才被插入vt4

 5.GROUP BY:按GROUP BY子句中的列列表對vt4中的行分組生成vt5

 6.CUBE|ROLLUP:把超組(supergroups)插入vt6 生成vt6

 7.HAVING:對vt6應用HAVING篩選器只有使< having_condition> 為true的組才插入vt7

 8.SELECT:處理select列表產生vt8

 9.DISTINCT:將重復的行從vt8中去除產生vt9

 10.ORDER BY:將vt9的行按order by子句中的列列表排序生成一個游標vc10

 11.TOP:從vc10的開始處選擇指定數量或比例的行生成vt11 并返回調用者

對比總結

MongoDB和SQL Server都是先SELECT列表后,再到內存中排序,最后取前幾行。

對于內存溢出的優化

MongoDB查詢優化的原則可參考:

Optimize Query Performance
https://docs.mongodb.com/manual/tutorial/optimize-query-performance-with-indexes-and-projections/

有的開發會干脆將數據取出來后在程序里排序,這個不推薦,因為這樣同樣占用過多內存,沒有從根本上解決這個問題。

比較推薦的方案有三個:
1.優化查詢和索引。
2.減少輸出列(限制輸出列個數)或行(如limit函數,或限制輸入查詢_id數量)。
3.將查詢分2步,第1步只輸出_id,第2步再通過_id查明細。
都可以解決內存中排序溢出問題。

從3.0版本開始的系統參數調優

從3.0版本開始可以通過修改參數值internalQueryExecMaxBlockingSortBytes來增加內存排序大小限制。

先來看看所有支持的參數:

use admin db.runCommand( { getParameter : 1, "internalQueryExecMaxBlockingSortBytes" : 1 } )

再來看看如何設置:

db.adminCommand({setParameter: 1, internalQueryExecMaxBlockingSortBytes: <limit in bytes>})

另外有需要云服務器可以了解下創新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

分享文章:深入MongoDB內存溢出調優-創新互聯
標題URL:http://vcdvsql.cn/article48/pgiep.html

成都網站建設公司_創新互聯,為您提供云服務器靜態網站電子商務企業建站網站改版商城網站

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

手機網站建設