gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with interval of inbox checking and speed of sending


From: alonso
Subject: problem with interval of inbox checking and speed of sending
Date: Fri, 27 Jul 2012 18:59:35 -0600
User-agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

Hi. I believe there is a problem in smsd/lowlevel.c in the RealConnect function.  There is a sleep (smsdConfig.refreshInt);  and during this time it is not possible to send sms because they are only sent after the sleep is over and the program loops back to check for events.   Apparently the sending thread sends only one event at a time and then waits for a response. So in each of the loops of RealConnect it is possible to send only one sms.

I found this because I thought that by having a larger interval of inbox checking that might leave more time to speed up sending. So I ran smsd -i 6  , but then I noticed that it was taking 6 or more seconds to send each sms.  Also the real interval of checking is not 6 seconds because the program might spend some time sending an sms or doing some other event and then it sleeps the same 6 seconds on each loop. So the time between checks of the inbox will be several seconds more.

I changed the code so that it does not check the inbox if the 6 seconds have not elapsed, and in the meantime it continues to check for new events, so it will send any sms in the outbox.
I also applied the transaction patch discussed in previous emails. And I also made a change in smsd/mysql.c

    numerror = 0;
    do {   
      error = WriteSMS (&sms);
      sleep (1);
    } while ((error == GN_ERR_TIMEOUT || error == GN_ERR_FAILED) && numError++ < 3);


This has the problem that it will always sleep 1 second. I think this was intended to sleep only when there was an error before the next try?
So i changed it to

  if(numError)  sleep (1);
  error = WriteSMS (&sms);

Now it will not sleep when there is no error.

My setup is 2 smsd running each with a usb phone , serial and AT. The test is send 70 messages from phone 1 to phone 2. At the same time send 70 messages from phone 2 to itself. So phone 2 also receives 140 sms during this test.

Sending only times (phone 1) where reduced from 8 minutes to 3 minutes with the transaction patch. With the sleep fix in mysql.c this was reduced to 2 minutes. And with the RealConnect fix I am able to send 70 sms in 1 minute.
After fixing RealConnect one can now use -i 6 but this does not make any difference in speed of sending.

Without the transaction patch phone 2 would always take the exact same time as phone 1 even when phone 1 is doing much less work (8 minutes). I suspect the database locks don't allow phone 1 to go any faster as it waits for phone 2 to send each message. This is not the expected behaviour as I understand the MySQL 5.0 manuals.
With the transaction patch phone 2 takes about 6 minutes. The sleep fix in mysql.c made no difference. With the RealConnect fix it takes less than 5 minutes.
Using -i 6 makes phone 2 slower, taking 7 minutes.




This is how the RealConnect function is looking now: (my changes in bold)

static void RealConnect (void *phone)
{
  gn_data *data;
  gn_sms_status SMSStatus = {0, 0, 0, 0};
  gn_sms_folder SMSFolder;
  PhoneEvent *event;
  gn_error error;
  int consecutive_errors = 0;

//alonso
  int loopStartTime = 0;
  int now = 0;	
  int hasEvents = 0;

  data = "" (1, sizeof (gn_data));
  
  gn_log_xdebug ("Initializing connection...\n");

  if (fbusinit ((gchar *)phone) != GN_ERR_NONE)
  {
    free (data);
    exit (1);
  }

  if (smsdConfig.memoryType == GN_MT_XX) {
    if (phoneMonitor.supported & PM_FOLDERS)
      smsdConfig.memoryType = GN_MT_IN;
    else
      smsdConfig.memoryType = GN_MT_SM;
  }

  gn_log_xdebug ("Phone connected. Starting monitoring...\n");

  while (1) 
  {
    loopStartTime = time(NULL);  //alonso

    while (1) { //alonso

     hasEvents = 0;  //alonso


     pthread_mutex_lock (&smsMutex);
    
     /* The event queue must be processed before RefreshSMS ()! */
     while ((event = RemoveEvent ()) != NULL)
     { 
	//alonso
	hasEvents=1;

      gn_log_xdebug ("Processing Event: %d\n", event->event);
      if (event->event <= Event_Exit)
        if ((error = DoAction[event->event] (event->data)) != GN_ERR_NONE)
          g_print (_("Event %d failed with return code %d!\n"), event->event, error);
      g_free (event);
     }

//alonso
     now = time(NULL);
     g_print (_("seconds since start of loop %ld!\n"), now - loopStartTime);
     if( now - loopStartTime < smsdConfig.refreshInt) {
	//no need to RefreshSMS yet
	pthread_mutex_unlock (&smsMutex);

	//if there were events processed then go immediately to check for more, otherwise wait a bit
	if(!hasEvents) usleep(200000);
     }
     else
	break;
    }//alonso end new loop

  
    if (phoneMonitor.supported & PM_FOLDERS)
    {
      data->sms_folder = &SMSFolder;
      SMSFolder.folder_id = smsdConfig.memoryType;
      if ((error = gn_sm_functions (GN_OP_GetSMSFolderStatus, data, sm)) == GN_ERR_NONE)
      {
        gn_log_xdebug ("GN_OP_GetSMSFolderStatus returned (number) %d\n",
                       SMSFolder.number);
        gn_log_xdebug ("phoneMonitor.sms.number %d\n",
                       phoneMonitor.sms.number);
        if (phoneMonitor.sms.number != SMSFolder.number)
        {
          RefreshSMS (SMSFolder.number);
        }
//        phoneMonitor.sms.unRead = 0;
      }
    }
    else
    {
      gn_memory_status dummy;
      dummy.memory_type = smsdConfig.memoryType;

      data->sms_status = &SMSStatus;
      data->memory_status = &dummy;
      if ((error = gn_sm_functions (GN_OP_GetSMSStatus, data, sm)) == GN_ERR_NONE)
      {
        gn_log_xdebug ("GN_OP_GetSMSStatus returned (number, unread) %d, %d\n",
                       SMSStatus.number, SMSStatus.unread);
        gn_log_xdebug ("phoneMonitor.sms.number %d\n",
                       phoneMonitor.sms.number);
        if (/* phoneMonitor.sms.unRead != SMSStatus.unread || */
            phoneMonitor.sms.number != SMSStatus.number)
        {
          RefreshSMS (SMSStatus.number);
        }
//        phoneMonitor.sms.unRead = SMSStatus.unread;
      }
    }
    
    pthread_mutex_unlock (&smsMutex);
    
    if (error != GN_ERR_NONE)
    {
      if (error == GN_ERR_TIMEOUT)
      {
        g_print (_("Timeout in file %s, line %d, restarting connection.\n"),
                 __FILE__, __LINE__);
        break;
      }
      else
      {
        g_print ("%s:%d error: %d, %s\n", __FILE__, __LINE__, error, gn_error_print(error));
	consecutive_errors++;
	if (consecutive_errors > MAX_CONSECUTIVE_ERRORS)
	{
	  g_print (_("Too many consecutive errors, restarting connection.\n"));
	  break;
	}
      }
    }
    else
    {
      consecutive_errors = 0;
    }

    //alonso  sleep here not needed
	//sleep (smsdConfig.refreshInt);
  }

  free (data);
}



Thanks

Alonso Acuña

reply via email to

[Prev in Thread] Current Thread [Next in Thread]