Linux RPC调用很慢

时间:2016-01-19 10:25:31

标签: c linux rpc

以下RPC程序在Fedora上执行速度非常慢。 如果我在<!DOCTYPE html> <html> <head> <style> #buttonGroup { width: 100%; margin: 0 auto; } #acceptButton { width: 50%; float: left; } #rejectButton { width: 50%; float: left; } </style> </head> <body> <div id=buttonGroup> <div id="acceptButton"> <p align="center"><!--[if mso]> <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="{!$Label.Site_URL_Prefix}campaignAccept?leadid={!CampaignMember.LeadId}{!Lead.Id}&contactid={!CampaignMember.ContactId}{!Contact.Id}&campaignId={!Campaign.Id}&action=Accept" style="height:40px;v-text-anchor:middle;width:200px;" arcsize="13%" strokecolor="#31b934" fillcolor="#2c772e"> <w:anchorlock/> <center style="color:#ffffff;font-family:sans-serif;font-size:13px;font-weight:bold;">Accept</center> </v:roundrect> <![endif]--><a href="{!$Label.Site_URL_Prefix}campaignAccept?leadid={!CampaignMember.LeadId}{!Lead.Id}&contactid={!CampaignMember.ContactId}{!Contact.Id}&campaignId={!Campaign.Id}&action=Accept" style="background-color:#31b934;border:1px solid #2c772e;border-radius:5px;color:#ffffff;display:inline-block;font-family:sans-serif;font-size:13px;font-weight:bold;line-height:40px;text-align:center;text-decoration:none;width:200px;-webkit-text-size-adjust:none;mso-hide:all;">Accept</a></p> </div> <div id="rejectButton> <p align="center"><!--[if mso]> <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="{!$Label.Site_URL_Prefix}campaign?leadid={!CampaignMember.LeadId}{!Lead.Id}&contactid={!CampaignMember.ContactId}{!Contact.Id}&campaignId={!Campaign.Id}&action=Reject" style="height:40px;v-text-anchor:middle;width:200px;" arcsize="13%" strokecolor="#d12835" fillcolor="#921620"> <w:anchorlock/> <center style="color:#ffffff;font-family:sans-serif;font-size:13px;font-weight:bold;">Decline</center> </v:roundrect> <![endif]--><a href="{!$Label.Site_URL_Prefix}campaign?leadid={!CampaignMember.LeadId}{!Lead.Id}&contactid={!CampaignMember.ContactId}{!Contact.Id}&campaignId={!Campaign.Id}&action=Reject" style="background-color:#d12835;border:1px solid #921620;border-radius:5px;color:#ffffff;display:inline-block;font-family:sans-serif;font-size:13px;font-weight:bold;line-height:40px;text-align:center;text-decoration:none;width:200px;-webkit-text-size-adjust:none;mso-hide:all;">Decline</a></p> </div> </div> </body> </html>中将name缓冲区的大小从999个字符更改为512,那么它的工作速度很快。 我不知道为什么。 如果有人知道原因,请告诉我!

注意:请编译以下程序并执行服务器然后执行客户端。 (对我来说,30个循环需要3秒钟。

llist.c

llist.x

llist_svc_proc.c

#include "llist.h"
#define PRINT_TIME  (!gettimeofday(&tv, NULL) && printf(" %lf",tv.tv_sec+(tv.tv_usec/1000000.0)))

struct timeval tv;

int main(int argc, char *argv[])
{
CLIENT *cl;
int *result,i=0;

cl = clnt_create("localhost", PRINTER, PRINTER_V1, "tcp");
if (cl == NULL) {
            clnt_pcreateerror("Cant Create Client Handle");
    printf("error: could not connect to server.\n");
    return 1;
}

    ST1 key[1];
    ST1_stuff  key_x;

    /*key_x.ST1_stuff_val = key;
    key_x.ST1_stuff_len = 1;
*/
    while(i<30)
    {
            printf("\n %d -> start - ",i);
            PRINT_TIME;
            result = sei_conf_test_keys2_1(&key_x,cl);
            if (result == NULL) {
    printf("error: RPC failed!\n");
    return 1;
    }
            printf("\nresult = %d ",*result);
            i++;
            printf("\n end - ");
            PRINT_TIME;
            printf("\n -------------------------------------");
    }

    return 0;
}

llist.x

#include <stdlib.h>
#include "llist.h"

int result;

int *sei_conf_test_keys2_1_svc(ST1 *lst, struct svc_req *req)
{
   result = 0;
   return &result;
}

生成文件

 struct s1{
    char name[999];              /* <===== HERE */
 };
 typedef struct s1 ST1;

 typedef ST1 ST1_stuff[1];


 program PRINTER {
    version PRINTER_V1 {
            int SEI_CONF_TEST_KEYS2(ST1_stuff) = 10;
    } = 1;
 } = 0x2fffffff;

1 个答案:

答案 0 :(得分:1)

时间的增加似乎与允许的最大值有关 一个TCP包中的数据。

使用网络分析仪可以看出,大小为999的 167个包 而对于大小512,在客户端和服务器之间仅发送大约 79个分组。 每个包的最大数据大小似乎是4000字节。

如果您需要性能,请考虑切换到UDP,这似乎不受最大包大小和额外开销的限制。