Slow response by arduino server being controlled by python client

I'm trying to make a python client communicate with an arduino server. The python client asks the server to take a measurement from the sonar, and then server just sends a confirmation message and then takes the message.

The client:

client.py

import socket
import time

while True:
    try:
        client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client_socket.connect(("192.168.0.250", 10220))
        data = "GET\nSONAR\n\n"
        print 'send to server: ' + data
        client_socket.send(data)
        receive = client_socket.recv(2048)
        print receive
        client_socket.close()
        time.sleep(0.1)
    except Exception as msg:
        print msg
and the server:

server.ino

#include <avr/wdt.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>

//localClient parameters, for sending data to the server.
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x03, 0x58};
byte ip[] = {192,168,0,250};
byte server[] = {192, 168, 0, 100};
int serverPort = 8220;

//Server parameters, for acting like a server.
int pollPort = serverPort + 2000;
EthernetServer pollServer = EthernetServer(pollPort);
//char inString[32]; // string for incoming serial data

//sonar stuff
String content_string;
int NUM_SONARS = 1;
int sonarPin[] = {2, 3, 4, 5};
int triggerPin = 6;
int sonarThreshold = 12.0;
int sonarState[] = {0, 0, 0, 0};
long pulse;
int numPulses = 3;
int pulseArray[] = {0,0,0,0,0};
int filteredMode = 0;
float time;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip);

  wdt_enable(WDTO_8S);

  pollServer.begin();

  for(int i = 0; i < NUM_SONARS; i++) {
    pinMode(sonarPin[i], INPUT);
  }
  pinMode(triggerPin, OUTPUT);
  digitalWrite(triggerPin, LOW);
  time = 0;
}

void loop() {
  wdt_reset();
  time = millis();

  EthernetClient pollClient = pollServer.available();
  if (pollClient) {
    boolean currentLineIsBlank = true;
    String receivingString = "";
    while (pollClient.connected()) {
      //while the socket is open
      if(pollClient.available()) {
        //and there is something to read on the port, then read the available characters
        char c = pollClient.read();
        receivingString += c;
        if (c == '\n' && currentLineIsBlank) {
          Serial.print("String received -- ");
          Serial.print(receivingString);
          Serial.print("at ");
          Serial.println(time);
          pollClient.println("Received message.");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // parse the incoming data
    String command = split(receivingString,'\n',0);
    String payload = split(receivingString,'\n',1);


    String key = split(payload,'=',0);
    String value = split(payload,'=',1);

    //PARSE THE KEY AND VALUE NOW
    if(command == "GET") {
      //if I received a GET command, send a response to the client.

      if(key == "SONAR") {
        pingSonars();
      }
    }
}

String split(String data, char delimiter, int index) {
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==delimiter || i==maxIndex){
        found++;
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }

  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void isort(int *a, int n) {
  for (int i = 1; i < n; ++i) {
    int j = a[i];
    int k;
    for (k = i - 1; (k >= 0) && (j < a[k]); k--) {
      a[k + 1] = a[k];
    }
    a[k + 1] = j;
  }
}

int mode(int *x,int n){

  int i = 0;
  int count = 0;
  int maxCount = 0;
  int mode = 0;
  int bimodal;
  int prevCount = 0;
  while(i<(n-1)){
    prevCount=count;
    count=0;
    while(x[i]==x[i+1]){
      count++;
      i++;
    }
    if(count>prevCount&count>maxCount){
      mode=x[i];
      maxCount=count;
      bimodal=0;
    }
    if(count==0){
      i++;
    }
    if(count==maxCount){//If the dataset has 2 or more modes.
      bimodal=1;
    }
    if(mode==0||bimodal==1){//Return the median if there is no mode.
      mode=x[(n/2)];
    }
    return mode;
  }
}

void printArray(int *a, int n) {

  for (int i = 0; i < n; i++)
  {
    Serial.print(a[i], DEC);
    Serial.print(' ');
  }
  Serial.println();
}

void pingSonars() {
  digitalWrite(6, HIGH);
    for(int i = 0; i < NUM_SONARS; i++) {
    for(int j = 0; j < numPulses; j++) {
      pulse = pulseIn(sonarPin[i], HIGH);
      pulseArray[j] = pulse/147; //convert to inches -- 147 uS per inches
      delay(5);
    }
    isort(pulseArray, numPulses);
    filteredMode = mode(pulseArray,numPulses);
    //printArray(pulseArray,numPulses);
    Serial.print("Filtered distance for Sonar ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(filteredMode);
    if((filteredMode < sonarThreshold) && !sonarState[i]) {
      //if we are closer than the threshold and previously were not, this is a rising edge:
      Serial.print("Sonar ");
      Serial.print(i);
      Serial.println(" triggered!");
      sonarState[i] = 1;
    }
    else if (filteredMode > sonarThreshold && sonarState[i]) {
    //if we are greater than the threshold and previously were, this is a falling edge:
      Serial.print("Sonar ");
      Serial.print(i);
      Serial.println(" falling!");
      sonarState[i] = 0;
    }
  }
}

The client sends requests at about a 100 millisecond interval, but the server seems to be able to respond much slower than that -- maybe at 2-3 times per second. What's limiting the rate of communication? Is it possible that the serial printouts are actually limiting it? Or does it have to do with how I'm opening/closing/listening to the port in the server code?

thanks for your help!

Is it possible that the serial printouts are actually limiting it? Or does it have to do with how I'm opening/closing/listening to the port

Yes both things will slow it down.

How would you recommend refactoring the port opening / closing to optimize for speed?

Open it once in the start up function and close it when you shut down the sketch ( if at all )