免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Redis主從結(jié)構(gòu)主節(jié)點(diǎn)執(zhí)行寫入后wait命令對(duì)性能的影響

這里的Redis主從結(jié)構(gòu)可以是簡(jiǎn)單的主從,sentinel,redis cluster中的主從等。

wait命令的作用:
此命令將阻塞當(dāng)前客戶端,直到當(dāng)前Session連接(主節(jié)點(diǎn)上)所有的寫命令都被傳送到指定數(shù)據(jù)量的slave節(jié)點(diǎn)。
如果到達(dá)超時(shí)(以毫秒為單位),則即使尚未完全傳送到達(dá)指定數(shù)量的salve節(jié)點(diǎn),該命令也會(huì)返回(成功傳送到的節(jié)點(diǎn)的個(gè)數(shù))。
該命令將始終返回確認(rèn)在WAIT命令之前發(fā)送的寫命令的副本數(shù)量,無論是在達(dá)到指定數(shù)量的副本的情況下,還是在達(dá)到超時(shí)的情況下。
具體說就是:比如對(duì)于1主2從的結(jié)構(gòu),Wait要求3秒鐘之內(nèi)傳送到2個(gè)節(jié)點(diǎn),但是達(dá)到超時(shí)時(shí)間3秒鐘之后只成功傳送到了1個(gè)slave節(jié)點(diǎn)上,此時(shí)wait也不會(huì)繼續(xù)阻塞,而是返回成功傳送的節(jié)點(diǎn)個(gè)數(shù)(1)。
有點(diǎn)類似于MySQL的半同步復(fù)制,但是效果完全不能跟半同步相比,因?yàn)镽edis本身沒有回滾的功能,這里的wait命令發(fā)起之后,即便是超時(shí)時(shí)間之后沒有送到任何一個(gè)slave節(jié)點(diǎn),主節(jié)點(diǎn)也不會(huì)回滾。
wait命令無法保證Redis主從之間的強(qiáng)一致,不過,在主從、sentinel和Redis群集故障轉(zhuǎn)移中,wait能夠增強(qiáng)(僅僅是增強(qiáng),但不是保證)數(shù)據(jù)的安全性。

既然wait命令在當(dāng)前連接之后會(huì)等待指定數(shù)量的從節(jié)點(diǎn)確認(rèn),其主節(jié)點(diǎn)的寫入效率必然會(huì)收到一定程度的影響,那么這個(gè)影響有多大?
這里做一個(gè)簡(jiǎn)單的測(cè)試,環(huán)境2核4G的宿主機(jī),docker下的集群3主3從的Redis集群,因此不用考慮網(wǎng)絡(luò)延遲,在執(zhí)行寫入操作之后,使用兩個(gè)Case,對(duì)比使不使用wait命令等待傳送到salve的效率,
1,單線程循環(huán)寫入100000個(gè)key值
2,多線程并發(fā),10個(gè)線程每個(gè)線程寫入10000個(gè)key,一共寫入100000個(gè)key

Case1:單線程循環(huán)寫入100000個(gè)key值
結(jié)論:不使用wait命令,整體耗時(shí)33秒,集群中單個(gè)節(jié)點(diǎn)的TPS為1000左右;使用wait命令,整體耗時(shí)72秒,集群中單個(gè)節(jié)點(diǎn)的TPS為480左右,整體效率下降了50%多一點(diǎn)

單線程不使用WAIT

單線程使用WAIT(redis_conn.execute_command('wait', 1, 0))

 

Case2:多線程循環(huán)寫入100000個(gè)key值
結(jié)論:不使用wait命令,整體耗時(shí)19秒,集群中單個(gè)節(jié)點(diǎn)的TPS為1700左右;使用wait命令,整體耗時(shí)36秒,集群中單個(gè)節(jié)點(diǎn)的TPS為900左右,整體效率與單線程基本上一致,下降了50%多一點(diǎn)

多線程不使用WAIT,單節(jié)點(diǎn)上TPS可達(dá)到1700左右

多線程使用WAIT,單節(jié)點(diǎn)上TPS可達(dá)到850左右

鑒于在多線程模式下,CPU負(fù)載接近于瓶頸,因此不能再加更多的線程數(shù),測(cè)試數(shù)據(jù)也僅供參考。

 

總結(jié):
wait能夠在主節(jié)點(diǎn)寫入命令之后,通過阻塞的方式等待數(shù)據(jù)傳送到從節(jié)點(diǎn),wait能夠增強(qiáng)(但不保證)數(shù)據(jù)的安全性。
其代價(jià)或者說性能損耗也是不小的,通過以上測(cè)試可以看出,即便是不考慮網(wǎng)絡(luò)傳輸延遲的情況下,其性能損耗也超出了50%。

#!/usr/bin/env python# coding:utf-8import sysimport timeimport datetimefrom rediscluster import StrictRedisClusterimport threadingfrom time import ctime,sleepdef redis_cluster_write():    redis_nodes = [ {'host':'172.18.0.11','port':8888},                    {'host':'172.18.0.12','port':8888},                    {'host':'172.18.0.13','port':8888},                    {'host':'172.18.0.14','port':8888},                    {'host':'172.18.0.15','port':8888},                    {'host':'172.18.0.16','port':8888}]    try:        redis_conn = StrictRedisCluster(startup_nodes=redis_nodes,password='******')    except Exception:        raise Exception    redis_conn.config_set('cluster-require-full-coverage', 'yes')    counter = 0    for i in range(0,100000):        counter = counter+1        redis_conn.set('key_'+str(i),'value_'+str(i))        #redis_conn.execute_command('wait', 1, 0)        if counter == 1000:            print('insert 1000 keys '+str(str(datetime.datetime.now())))            counter = 0def redis_concurrence_test(thread_id):    redis_nodes = [ {'host':'172.18.0.11','port':8888},                    {'host':'172.18.0.12','port':8888},                    {'host':'172.18.0.13','port':8888},                    {'host':'172.18.0.14','port':8888},                    {'host':'172.18.0.15','port':8888},                    {'host':'172.18.0.16','port':8888}]    try:        redis_conn = StrictRedisCluster(startup_nodes=redis_nodes, password='******')    except Exception:        raise Exception    redis_conn.config_set('cluster-require-full-coverage', 'yes')    counter = 0    for i in range(0, 10000):        counter = counter + 1        redis_conn.set('key_' + str(thread_id)+'_'+str(counter), 'value_' + str(i))        #redis_conn.execute_command('wait', 1, 0)        if counter == 1000:            print(str(thread_id)+':insert 1000 keys ' + str(str(datetime.datetime.now())))            counter = 0if __name__ == '__main__':    #redis_cluster_write()    threads = []    for i in range(10):        t = threading.Thread(target=redis_concurrence_test, args=(i,))        threads.append(t)    begin_time = ctime()    for t in threads:        t.setDaemon(True)        t.start()    for t in threads:        t.join()


https://redis.io/commands/wait

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
windows下redis基礎(chǔ)操作與主從復(fù)制 從而 數(shù)據(jù)備份和讀寫分離
Redis三主三從集群搭建
首發(fā)丨360開源的類Redis存儲(chǔ)系統(tǒng):Pika
狂神說Java——Redis最全教程
Redis單例、主從模式、sentinel以及集群的配置方式及優(yōu)缺點(diǎn)對(duì)比
Redis高可用方案
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服