LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   difficulties with large files and system call read/write (https://www.linuxquestions.org/questions/programming-9/difficulties-with-large-files-and-system-call-read-write-220945/)

jwstric2 08-22-2004 01:17 PM

difficulties with large files and system call read/write
 
The scenrio is as follows:

I doing a impact tests for a network application. Its being done on a local network. Transfer of information involve opening a tcp socket then closing upon transfer, like an http request (1MB transfer chunks). The performance test is a disk impact tests, writing a large file 4-8Gigs and taking a median of three or four of these tests times. The writes occur continously, no pause between file writes in the tests. Then the network application is run during this tests to observe what impact it has on the test's time.

The problem is the test running with the application causes the socket read to seem to hang on the application receving the data (this is the side the disk impact test is running on). Thus when the performance tests starts read(socket, xbuffer ,count) hangs indefinately, even when the performance test completes. It never returns an error, or indicate an unsucessful read, it just hangs.

I know the socket connection is still good, I can verfiy that from both side. I also verfied that the sender side indicates that the actual socket would block so it doesn;t send data. Why would it actually indicate the socket is busy even though nothing has been sent to it?


The tests are running on Fedora Core 2 machines.
Any ideas??

jwstric2 08-22-2004 03:21 PM

I found out where my code is failing, buts its a strange fail..

The server uses the following code. The request for the data is a udp packet which will be able to reselect another machine in the long run but for now it simply assumes the machine is up.

Code:

void putMorsel(int myNode, struct data_request *request){
  struct scavenger_morsel_msg msg;
  struct data_request_holder *data_request_holder;
  int server_sockfd;
  int bind_port;
  int retval;
  fd_set tmp_rfds;
  int tcp_buffer_size = TCP_BUFFER_SIZE;
  struct timeval accept_timeout = {0, 0};

  /*
  * socket: create the parent socket
  */
  server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (server_sockfd < 0)
    return;


  bind_port = bindServerSocket(server_sockfd);
  if(bind_port < 0){
    return;
  }
 
  msg.hdr.orig = myNode;
  msg.hdr.flags = 0;
  msg.flags = 0;
  msg.morsel_id = request->morsel_id;
  msg.port = bind_port; 

  FD_ZERO(&tmp_rfds);
  FD_SET(server_sockfd, &tmp_rfds); 
  listen(server_sockfd, 1); 

  send:

  pSend(request->benefactorNode, MSG_SCAVENGER_PUT, 0, 1, sizeof(msg), &msg);
  accept_timeout.tv_sec = TIMEOUT;
  retval = select_non_interruptible(NUM_PORTS, &tmp_rfds, NULL, NULL, &accept_timeout);

  if(retval == 0){
    goto send;
  }
  else if (retval > 0){
    data_request_holder = (struct data_request_holder *)malloc(sizeof(struct data_request_holder));
    if(!data_request_holder){
      goto cleanup;
    }   
    data_request_holder->client_sockfd = accept(server_sockfd, NULL, 0);   
    setsockopt(data_request_holder->client_sockfd, SOL_SOCKET, SO_SNDBUF, &tcp_buffer_size, sizeof(tcp_buffer_size));
    if(data_request_holder->client_sockfd < 0){
      goto cleanup;
    }
    data_request_holder->curr_transfer_size = 0;
    data_request_holder->request_data = request;
    data_request_holder->request_type = PUT_REQUEST;

    if(!l_insert(request_list, data_request_holder)){
      free(data_request_holder);
      goto cleanup;
    }
    FD_SET(data_request_holder->client_sockfd, &wfds);
  }
  else{
    return;
  }
   
  cleanup:

  FD_CLR(server_sockfd, &tmp_rfds);
  close(server_sockfd);

 
}

Somwtimes the line: retval = select_non_interruptible(NUM_PORTS, &tmp_rfds, NULL, NULL, &accept_timeout); returns 0 even though it appears the client actually connected to the server. So the client connected somehow but the server can;t distinguish this. (the accept was never called)

kumarnine 08-22-2004 11:42 PM

use non_blocking option with sockfd
 
I think, it may be happening that ur socket is being blocked when the data is not available. so try the option of setting the socketfd with non-blocking option
fcntl(sockfd,NON_BLOCK,,...)..something like this..


All times are GMT -5. The time now is 08:09 AM.