怎么樣更好的優(yōu)化Redis性能?

大家好炭序,我是一名Java后端程序員,每天開(kāi)心的擼CRUD;

你猜這次我又要寫(xiě)個(gè)啥沒(méi)有卵用的知識(shí)點(diǎn)呢?

不好意思苍日,問(wèn)的稍微有點(diǎn)早了惭聂,啥提示都沒(méi)給,咋猜呢相恃,對(duì)吧?

今天早上老板把我叫到辦公室辜纲,對(duì)我說(shuō),“公司最近接了個(gè)電商小程序單子,你和王二狗侨歉,張SD參與下需求分析和設(shè)計(jì)屋摇,然后下個(gè)月開(kāi)發(fā)揩魂,3個(gè)月內(nèi)完成測(cè)試幽邓,上線交付”。

WC火脉,WC牵舵,WC

。倦挂。畸颅。。方援。没炒。。

“老板犯戏,老板送火,我沒(méi)學(xué)過(guò)微信小程序,我是個(gè)Java后端程序員先匪,你再招一個(gè)前端微信小程序開(kāi)發(fā)吧”种吸,我很低聲的跟老板說(shuō)。

老板很大聲的吼道呀非,“不會(huì)的東西坚俗,不會(huì)自己學(xué)嗎?招新不要錢(qián)嗎?你知道今年行情有多差嗎,接單子容易嗎?不想干就G?”

image-20211031155803192

我平很想發(fā)火懟老板岸裙,但是突然想到;

上有農(nóng)村年邁父母猖败,下有襁褓小兒,媳婦還辭職在出租房帶孩子降允。

我就低聲回復(fù):“噢恩闻,噢,好的拟糕,好的判呕,我學(xué)∷椭停”

屌絲的人生就是這樣侠草,總得向生活低頭。

努力學(xué)習(xí)吧!!!等我技術(shù)牛逼了犁嗅,把老板炒了边涕。

下面直接上超重量級(jí)干貨:

回歸正題:怎么樣更好的優(yōu)化Redis性能?

一、優(yōu)化的一些建議

1、盡量使用短的key

當(dāng)然在精簡(jiǎn)的同時(shí)功蜓,不要為了key的“見(jiàn)名知意”园爷。對(duì)于value有些也可精簡(jiǎn),比如性別使用0式撼、1童社。

2、避免使用keys

keys , 這個(gè)命令是阻塞的著隆,即操作執(zhí)行期間扰楼,其它任何命令在你的實(shí)例中都無(wú)法執(zhí)行。當(dāng)redis中key數(shù)據(jù)量小時(shí)到無(wú)所謂美浦,數(shù)據(jù)量大就很糟糕了弦赖。所以我們應(yīng)該避免去使用這個(gè)命令∑直妫可以去使用SCAN,來(lái)代替蹬竖。

3、在存到Redis之前先把你的數(shù)據(jù)壓縮下

redis為每種數(shù)據(jù)類(lèi)型都提供了兩種內(nèi)部編碼方式流酬,在不同的情況下redis會(huì)自動(dòng)調(diào)整合適的編碼方式币厕。

4、設(shè)置key有效期

我們應(yīng)該盡可能的利用key有效期康吵。比如一些臨時(shí)數(shù)據(jù)(短信校驗(yàn)碼)劈榨,過(guò)了有效期Redis就會(huì)自動(dòng)為你清除!

5、選擇回收策略(maxmemory-policy)

當(dāng)Redis的實(shí)例空間被填滿(mǎn)了之后晦嵌,將會(huì)嘗試回收一部分key同辣。根據(jù)你的使用方式,強(qiáng)烈建議使用 volatile-lru(默認(rèn)) 策略——前提是你對(duì)key已經(jīng)設(shè)置了超時(shí)惭载。但如果你運(yùn)行的是一些類(lèi)似于 cache 的東西旱函,并且沒(méi)有對(duì) key 設(shè)置超時(shí)機(jī)制,可以考慮使用 allkeys-lru 回收機(jī)制描滔,具體講解查看 棒妨。maxmemory-samples 3 是說(shuō)每次進(jìn)行淘汰的時(shí)候 會(huì)隨機(jī)抽取3個(gè)key 從里面淘汰最不經(jīng)常使用的(默認(rèn)選項(xiàng))。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n68" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">maxmemory-policy 六種方式 :
volatile-lru:只對(duì)設(shè)置了過(guò)期時(shí)間的key進(jìn)行LRU(默認(rèn)值)
allkeys-lru : 是從所有key里 刪除 不經(jīng)常使用的key
volatile-random:隨機(jī)刪除即將過(guò)期key
allkeys-random:隨機(jī)刪除
volatile-ttl : 刪除即將過(guò)期的
noeviction : 永不過(guò)期含长,返回錯(cuò)誤 </pre>

6券腔、使用bit位級(jí)別操作和byte字節(jié)級(jí)別操作來(lái)減少不必要的內(nèi)存使用

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n75" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">bit位級(jí)別操作:GETRANGE, SETRANGE, GETBIT and SETBIT
byte字節(jié)級(jí)別操作:GETRANGE and SETRANGE </pre>

7、盡可能地使用hashes哈希存儲(chǔ)

8拘泞、當(dāng)業(yè)務(wù)場(chǎng)景不需要數(shù)據(jù)持久化時(shí)纷纫,關(guān)閉所有的持久化方式可以獲得最佳的性能

數(shù)據(jù)持久化時(shí)需要在持久化和延遲/性能之間做相應(yīng)的權(quán)衡.

9、想要一次添加多條數(shù)據(jù)的時(shí)候可以使用管道

10陪腌、限制redis的內(nèi)存大小

(64位系統(tǒng)不限制內(nèi)存辱魁,32位系統(tǒng)默認(rèn)最多使用3GB內(nèi)存)

數(shù)據(jù)量不可預(yù)估烟瞧,并且內(nèi)存也有限的話(huà),盡量限制下redis使用的內(nèi)存大小染簇,這樣可以避免redis使用swap分區(qū)或者出現(xiàn)OOM錯(cuò)誤参滴。(使用swap分區(qū),性能較低锻弓,如果限制了內(nèi)存砾赔,當(dāng)?shù)竭_(dá)指定內(nèi)存之后就不能添加數(shù)據(jù)了,否則會(huì)報(bào)OOM錯(cuò)誤弥咪」澹可以設(shè)置maxmemory-policy,內(nèi)存不足時(shí)刪除數(shù)據(jù))

11聚至、SLOWLOG [get/reset/len]

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n84" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">slowlog-log-slower-than 它決定要對(duì)執(zhí)行時(shí)間大于多少微秒(microsecond,1秒 = 1,000,000 微秒)的命令進(jìn)行記錄本橙。
slowlog-max-len 它決定 slowlog 最多能保存多少條日志扳躬,當(dāng)發(fā)現(xiàn)redis性能下降的時(shí)候可以查看下是哪些命令導(dǎo)致的。 </pre>

二甚亭、管道測(cè)試

redis的管道功能在命令行中沒(méi)有贷币,但是redis是支持管道的,在java的客戶(hù)端(jedis)中是可以使用的:

image-20211031160004972

示例代碼:

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n93" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">//注:具體耗時(shí)亏狰,和自身電腦有關(guān)(博主是在虛擬機(jī)中運(yùn)行的數(shù)據(jù))
/**

  • 不使用管道初始化1W條數(shù)據(jù)
  • 耗時(shí):3079毫秒
  • @throws Exception
    */
    @Test
    public void NOTUsePipeline() throws Exception {
    Jedis jedis = JedisUtil.getJedis();
    long start_time = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) {
    jedis.set("aa_"+i, i+"");
    }
    System.out.println(System.currentTimeMillis()-start_time);
    }

/**

  • 使用管道初始化1W條數(shù)據(jù)
  • 耗時(shí):255毫秒
  • @throws Exception
    */
    @Test
    public void usePipeline() throws Exception {
    Jedis jedis = JedisUtil.getJedis();

long start_time = System.currentTimeMillis();
Pipeline pipelined = jedis.pipelined();
for (int i = 0; i < 10000; i++) {
pipelined.set("cc_"+i, i+"");
}
pipelined.sync();//執(zhí)行管道中的命令
System.out.println(System.currentTimeMillis()-start_time);
} </pre>

hash的應(yīng)用

示例:我們要存儲(chǔ)一個(gè)用戶(hù)信息對(duì)象數(shù)據(jù)役纹,包含以下信息: key為用戶(hù)ID,value為用戶(hù)對(duì)象(姓名暇唾,年齡促脉,生日等)如果用普通的key/value結(jié)構(gòu)來(lái)存儲(chǔ),主要有以下2種存儲(chǔ)方式:

1策州、將用戶(hù)ID作為查找key,把其他信息封裝成一個(gè)對(duì)象以序列化的方式存儲(chǔ) 缺點(diǎn):增加了序列化/反序列化的開(kāi)銷(xiāo)瘸味,引入復(fù)雜適應(yīng)系統(tǒng)(Complex adaptive system)修改其中一項(xiàng)信息時(shí),需要把整個(gè)對(duì)象取回够挂,并且修改操作需要對(duì)并發(fā)進(jìn)行保護(hù)旁仿。

image-20211031160035668

2、用戶(hù)信息對(duì)象有多少成員就存成多少個(gè)key-value對(duì) 雖然省去了序列化開(kāi)銷(xiāo)和并發(fā)問(wèn)題孽糖,但是用戶(hù)ID為重復(fù)存儲(chǔ)枯冈。

image-20211031160045876

Redis提供的Hash很好的解決了這個(gè)問(wèn)題,提供了直接存取這個(gè)Map成員的接口办悟。Key仍然是用戶(hù)ID, value是一個(gè)Map尘奏,這個(gè)Map的key是成員的屬性名,value是屬性值誉尖。( 內(nèi)部實(shí)現(xiàn):Redis Hashd的Value內(nèi)部有2種不同實(shí)現(xiàn)罪既,Hash的成員比較少時(shí)Redis為了節(jié)省內(nèi)存會(huì)采用類(lèi)似一維數(shù)組的方式來(lái)緊湊存儲(chǔ),而不會(huì)采用真正的HashMap結(jié)構(gòu),對(duì)應(yīng)的value redisObject的encoding為zipmap,當(dāng)成員數(shù)量增大時(shí)會(huì)自動(dòng)轉(zhuǎn)成真正的HashMap,此時(shí)encoding為ht )琢感。

image-20211031160058515

Instagram內(nèi)存優(yōu)化

Instagram可能大家都已熟悉丢间,當(dāng)前火熱的拍照App,月活躍用戶(hù)3億驹针。四年前Instagram所存圖片3億多時(shí)需要解決一個(gè)問(wèn)題:想知道每一張照片的作者是誰(shuí)(通過(guò)圖片ID反查用戶(hù)UID)烘挫,并且要求查詢(xún)速度要相當(dāng)?shù)膲K,如果把它放到內(nèi)存中使用String結(jié)構(gòu)做key-value:

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n107" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">HSET "mediabucket:1155" "1155315" "939"
HGET "mediabucket:1155" "1155315"
"939" </pre>

測(cè)試:1百萬(wàn)數(shù)據(jù)會(huì)用掉70MB內(nèi)存柬甥,3億張照片就會(huì)用掉21GB的內(nèi)存饮六。當(dāng)時(shí)(四年前)最好是一臺(tái)EC2的 high-memory 機(jī)型就能存儲(chǔ)(17GB或者34GB的,68GB的太浪費(fèi)了),想把它放到16G機(jī)型中還是不行的苛蒲。

Instagram的開(kāi)發(fā)者向Redis的開(kāi)發(fā)者之一Pieter Noordhuis詢(xún)問(wèn)優(yōu)化方案卤橄,得到的回復(fù)是使用Hash結(jié)構(gòu)。具體的做法就是將數(shù)據(jù)分段臂外,每一段使用一個(gè)Hash結(jié)構(gòu)存儲(chǔ). 由于Hash結(jié)構(gòu)會(huì)在單個(gè)Hash元素在不足一定數(shù)量時(shí)進(jìn)行壓縮存儲(chǔ)窟扑,所以可以大量節(jié)約內(nèi)存。這一點(diǎn)在上面的String結(jié)構(gòu)里是不存在的漏健。而這個(gè)一定數(shù)量是由配置文件中的hash-zipmap-max-entries參數(shù)來(lái)控制的嚎货。經(jīng)過(guò)實(shí)驗(yàn),將hash-zipmap-max-entries設(shè)置為1000時(shí)蔫浆,性能比較好殖属,超過(guò)1000后HSET命令就會(huì)導(dǎo)致CPU消耗變得非常大。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n113" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">HSET "mediabucket:1155" "1155315" "939"
HGET "mediabucket:1155" "1155315"
"939" </pre>

測(cè)試:1百萬(wàn)消耗16MB的內(nèi)存瓦盛∠聪裕總內(nèi)存使用也降到了5GB。當(dāng)然我們還可以?xún)?yōu)化谭溉,去掉mediabucket:key長(zhǎng)度減少了12個(gè)字節(jié)墙懂。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n118" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">HSET "1155" "315" "939"
HGET "1155" "315"
"939" </pre>

三、優(yōu)化案例

1扮念、修改linux中TCP監(jiān)聽(tīng)的最大容納數(shù)量

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n124" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">/proc/sys/net/core/somaxconn is set to the lower value of 128. </pre>

在高并發(fā)環(huán)境下你需要一個(gè)高backlog值來(lái)避免慢客戶(hù)端連接問(wèn)題损搬。注意Linux內(nèi)核默默地將這個(gè)值減小到/proc/sys/net/core/somaxconn的值,所以需要確認(rèn)增大somaxconn和tcp_max_syn_backlog兩個(gè)值來(lái)達(dá)到想要的效果柜与。 echo 511 > /proc/sys/net/core/somaxconn 注意:這個(gè)參數(shù)并不是限制redis的最大鏈接數(shù)巧勤。如果想限制redis的最大連接數(shù)需要修改maxclients,默認(rèn)最大連接數(shù)為10000

2弄匕、修改linux內(nèi)核內(nèi)存分配策略

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n130" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">錯(cuò)誤日志:WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.
To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or
run the command 'sysctl vm.overcommit_memory=1 </pre>

redis在備份數(shù)據(jù)的時(shí)候颅悉,會(huì)fork出一個(gè)子進(jìn)程,理論上child進(jìn)程所占用的內(nèi)存和parent是一樣的迁匠,比如parent占用的內(nèi)存為8G剩瓶,這個(gè)時(shí)候也要同樣分配8G的內(nèi)存給child,如果內(nèi)存無(wú)法負(fù)擔(dān)驹溃,往往會(huì)造成redis服務(wù)器的down機(jī)或者IO負(fù)載過(guò)高,效率下降延曙。所以?xún)?nèi)存分配策略應(yīng)該設(shè)置為 1(表示內(nèi)核允許分配所有的物理內(nèi)存豌鹤,而不管當(dāng)前的內(nèi)存狀態(tài)如何)。 內(nèi)存分配策略有三種 可選值:0枝缔、1布疙、2。 0愿卸, 表示內(nèi)核將檢查是否有足夠的可用內(nèi)存供應(yīng)用進(jìn)程使用;如果有足夠的可用內(nèi)存灵临,內(nèi)存申請(qǐng)?jiān)试S;否則,內(nèi)存申請(qǐng)失敗趴荸,并把錯(cuò)誤返回給應(yīng)用進(jìn)程儒溉。 1, 不管需要多少內(nèi)存赊舶,都允許申請(qǐng)睁搭。 2, 只允許分配物理內(nèi)存和交換內(nèi)存的大小(交換內(nèi)存一般是物理內(nèi)存的一半)笼平。

3、關(guān)閉Transparent Huge Pages(THP)

THP會(huì)造成內(nèi)存鎖影響redis性能舔痪,建議關(guān)閉

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n135" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Transparent HugePages :用來(lái)提高內(nèi)存管理的性能
Transparent Huge Pages在32位的RHEL 6中是不支持的
執(zhí)行命令 echo never > /sys/kernel/mm/transparent_hugepage/enabled
把這條命令添加到這個(gè)文件中/etc/rc.local </pre>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末寓调,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子锄码,更是在濱河造成了極大的恐慌夺英,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,858評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件滋捶,死亡現(xiàn)場(chǎng)離奇詭異痛悯,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)重窟,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)载萌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人巡扇,你說(shuō)我怎么就攤上這事扭仁。” “怎么了厅翔?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,282評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵乖坠,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我刀闷,道長(zhǎng)熊泵,這世上最難降的妖魔是什么仰迁? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,842評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮顽分,結(jié)果婚禮上徐许,老公的妹妹穿的比我還像新娘。我一直安慰自己怯邪,他們只是感情好绊寻,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,857評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著悬秉,像睡著了一般澄步。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上和泌,一...
    開(kāi)封第一講書(shū)人閱讀 51,679評(píng)論 1 305
  • 那天村缸,我揣著相機(jī)與錄音,去河邊找鬼武氓。 笑死梯皿,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的县恕。 我是一名探鬼主播东羹,決...
    沈念sama閱讀 40,406評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼忠烛!你這毒婦竟也來(lái)了属提?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,311評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤美尸,失蹤者是張志新(化名)和其女友劉穎冤议,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體师坎,經(jīng)...
    沈念sama閱讀 45,767評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡恕酸,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了胯陋。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蕊温。...
    茶點(diǎn)故事閱讀 40,090評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖惶岭,靈堂內(nèi)的尸體忽然破棺而出寿弱,到底是詐尸還是另有隱情,我是刑警寧澤按灶,帶...
    沈念sama閱讀 35,785評(píng)論 5 346
  • 正文 年R本政府宣布症革,位于F島的核電站,受9級(jí)特大地震影響鸯旁,放射性物質(zhì)發(fā)生泄漏噪矛。R本人自食惡果不足惜量蕊,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,420評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望艇挨。 院中可真熱鬧残炮,春花似錦、人聲如沸缩滨。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,988評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)脉漏。三九已至苞冯,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間侧巨,已是汗流浹背舅锄。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,101評(píng)論 1 271
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留司忱,地道東北人皇忿。 一個(gè)月前我還...
    沈念sama閱讀 48,298評(píng)論 3 372
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像坦仍,于是被迫代替她去往敵國(guó)和親鳍烁。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,033評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容