NotifyMyFrontEnd 函数背后的数据缓冲区(一)
生活随笔
收集整理的這篇文章主要介紹了
NotifyMyFrontEnd 函数背后的数据缓冲区(一)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
async.c的 ?
static void? NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid) 函數(shù)中的主要邏輯是這樣的:
復(fù)制代碼 if (whereToSendOutput == DestRemote)? { ? ? StringInfoData buf; ? ? pq_beginmessage(&buf, 'A'); ? ? //cursor 為 A ? ? pq_sendint(&buf, srcPid, sizeof(int32)); //追加 srcPid ? ? pq_sendstring(&buf, channel); ? ? //追加消息通道名 ? ?
if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3) ? ? pq_sendstring(&buf, payload); ? ? //追加消息字節(jié)流 ? ? pq_endmessage(&buf); ? ? //發(fā)送消息 ...... ? ? } 復(fù)制代碼 從上面看到,向StringInfoData 數(shù)據(jù)結(jié)構(gòu)填充信息,就表示信息發(fā)送結(jié)束。
static void?
NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid)
pq_endmessage是 pqformat.c 中函數(shù)它 調(diào)用 pqcomm.c 中的 pq_putmessage函數(shù) pq_putmessage 調(diào)用 internal_putbyes函數(shù) internal_putbyes 中 對(duì)pqSendPointer 進(jìn)行操作
關(guān)于 pqSendPointer/pqRevPointer,有如下定義:
-------------------------------------------------------------------------------------------- static char PqSendBuffer[PQ_BUFFER_SIZE]; static int PqSendPointer; /* Next index to store a byte in PqSendBuffer */
static char PqRecvBuffer[PQ_BUFFER_SIZE]; static int c; /* Next index to read a byte from PqRecvBuffer */ static int PqRecvLength; /* End of data available in PqRecvBuffer */ ---------------------------------------------------------------------------------------------
查閱文檔資料:《PostgreSQL數(shù)據(jù)庫(kù)內(nèi)核分析》中2.6.6中也有所說(shuō)明。
從 internal_putbyes 中的代碼邏輯看到,移動(dòng)指針未加任何鎖定機(jī)制。
復(fù)制代碼 static int ? ? internal_putbytes(const char *s, size_t len) ? ? { ? ? size_t ? ? amount; ? ? while (len > 0) ? ? { ? ? /* If buffer is full, then flush it out */ ? ? if (PqSendPointer >= PQ_BUFFER_SIZE) ? ? if (internal_flush()) ? ? return EOF;
amount = PQ_BUFFER_SIZE - PqSendPointer; ? ? if (amount > len) ? ? amount = len;
memcpy(PqSendBuffer + PqSendPointer, s, amount); ? ? PqSendPointer += amount; ? ? s += amount; ? ? len -= amount; ? ? } ? ? return 0; ? ? } ? ? 復(fù)制代碼 既然未加鎖,那么就可以這樣推斷:
在每一對(duì)客戶端和服務(wù)器端進(jìn)程之間,都有這樣一個(gè)內(nèi)存緩沖區(qū)。 換句話說(shuō),有多少個(gè)客戶端,就會(huì)產(chǎn)生多少個(gè)這樣的 內(nèi)存緩沖區(qū)。
具體如何,還需進(jìn)一步的驗(yàn)證。
本文轉(zhuǎn)自健哥的數(shù)據(jù)花園博客園博客,原文鏈接:http://www.cnblogs.com/gaojian/archive/2012/07/17/2594718.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
static void? NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid) 函數(shù)中的主要邏輯是這樣的:
復(fù)制代碼 if (whereToSendOutput == DestRemote)? { ? ? StringInfoData buf; ? ? pq_beginmessage(&buf, 'A'); ? ? //cursor 為 A ? ? pq_sendint(&buf, srcPid, sizeof(int32)); //追加 srcPid ? ? pq_sendstring(&buf, channel); ? ? //追加消息通道名 ? ?
if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 3) ? ? pq_sendstring(&buf, payload); ? ? //追加消息字節(jié)流 ? ? pq_endmessage(&buf); ? ? //發(fā)送消息 ...... ? ? } 復(fù)制代碼 從上面看到,向StringInfoData 數(shù)據(jù)結(jié)構(gòu)填充信息,就表示信息發(fā)送結(jié)束。
static void?
NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid)
pq_endmessage是 pqformat.c 中函數(shù)它 調(diào)用 pqcomm.c 中的 pq_putmessage函數(shù) pq_putmessage 調(diào)用 internal_putbyes函數(shù) internal_putbyes 中 對(duì)pqSendPointer 進(jìn)行操作
關(guān)于 pqSendPointer/pqRevPointer,有如下定義:
-------------------------------------------------------------------------------------------- static char PqSendBuffer[PQ_BUFFER_SIZE]; static int PqSendPointer; /* Next index to store a byte in PqSendBuffer */
static char PqRecvBuffer[PQ_BUFFER_SIZE]; static int c; /* Next index to read a byte from PqRecvBuffer */ static int PqRecvLength; /* End of data available in PqRecvBuffer */ ---------------------------------------------------------------------------------------------
查閱文檔資料:《PostgreSQL數(shù)據(jù)庫(kù)內(nèi)核分析》中2.6.6中也有所說(shuō)明。
從 internal_putbyes 中的代碼邏輯看到,移動(dòng)指針未加任何鎖定機(jī)制。
復(fù)制代碼 static int ? ? internal_putbytes(const char *s, size_t len) ? ? { ? ? size_t ? ? amount; ? ? while (len > 0) ? ? { ? ? /* If buffer is full, then flush it out */ ? ? if (PqSendPointer >= PQ_BUFFER_SIZE) ? ? if (internal_flush()) ? ? return EOF;
amount = PQ_BUFFER_SIZE - PqSendPointer; ? ? if (amount > len) ? ? amount = len;
memcpy(PqSendBuffer + PqSendPointer, s, amount); ? ? PqSendPointer += amount; ? ? s += amount; ? ? len -= amount; ? ? } ? ? return 0; ? ? } ? ? 復(fù)制代碼 既然未加鎖,那么就可以這樣推斷:
在每一對(duì)客戶端和服務(wù)器端進(jìn)程之間,都有這樣一個(gè)內(nèi)存緩沖區(qū)。 換句話說(shuō),有多少個(gè)客戶端,就會(huì)產(chǎn)生多少個(gè)這樣的 內(nèi)存緩沖區(qū)。
具體如何,還需進(jìn)一步的驗(yàn)證。
本文轉(zhuǎn)自健哥的數(shù)據(jù)花園博客園博客,原文鏈接:http://www.cnblogs.com/gaojian/archive/2012/07/17/2594718.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的NotifyMyFrontEnd 函数背后的数据缓冲区(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 梦到蛇咬腿预示着什么
- 下一篇: Item 14 In public c