Linux RPC call is slow

徘徊边缘 提交于 2019-12-23 15:10:32

问题


The following RPC program executes very slowly on Fedora. If I change the size of the name buffer from 999 characters to 512 in llist.x, then it's working fast. I don't know why. If anyone knows the reason, please let me know!

Note: Please compile the following programs and execute the server then the client. (For me, it takes 3 seconds for 30 loops.)

llist.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_svc_proc.c

#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;
}

llist.x

 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;

makefile

.SUFFIXES:
.SUFFIXES: .c .o
CLNT = llist
SRVR = llist_svc
CFLAGS = -g -Wall

SRVR_OBJ = llist_svc_proc.o llist_xdr.o llist_svc.o
CLNT_OBJ = llist.o llist_xdr.o llist_clnt.o

.c.o:
        gcc -c -o $@ $(CFLAGS) $<

default: $(CLNT) $(SRVR)

$(CLNT): $(CLNT_OBJ) llist.h
        gcc -o $(CLNT) $(CLNT_OBJ)

$(SRVR): $(SRVR_OBJ) llist.h
        gcc -o $(SRVR) $(SRVR_OBJ)
clean:
        rm *.o $(CLNT) $(SRVR)
        rm -f llist_xdr.c llist.h llist_clnt.c llist_svc.c
        rm core

回答1:


The time increase seems to be connected with the maximum allowed data in one TCP package.

Using a network analyser, one sees, that with size 999 there are 167 packages whereas with size 512 only about 79 packets are sent between client and server. The maximum data size per package seems to be 4000 bytes.

If you need performance, think about switching to UDP which seems not be limited by the maximum package size and additional overhead.



来源:https://stackoverflow.com/questions/34874296/linux-rpc-call-is-slow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!