Linux RPC Call Slow

The following RPC program runs very slowly on Fedora. If I change the buffer size namefrom 999 characters to 512 in llist.x, then it works quickly. I do not know why. If anyone knows the reason, please let me know!

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

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
+4
source share
1 answer

The increase in time is apparently due to the maximum allowable data in a single TCP packet.

, , 999 167 512 79 . 4000 .

, UDP, , , .

+1

Source: https://habr.com/ru/post/1624938/


All Articles