myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-244


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-244-g6820d66
Date: Sun, 16 May 2010 22:16:40 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  6820d668ea7afb38c9d32ac2105813e0263ebc74 (commit)
       via  a35680902adf62510957db1294de7aacc210ee1c (commit)
      from  59cad33ceac112256571971b333aff896b6b42aa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 6820d668ea7afb38c9d32ac2105813e0263ebc74
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon May 17 00:16:55 2010 +0200

    Be more conservative to destroy unused threads.

diff --git a/myserver/include/connections_scheduler/connections_scheduler.h 
b/myserver/include/connections_scheduler/connections_scheduler.h
index 6e79569..620638c 100644
--- a/myserver/include/connections_scheduler/connections_scheduler.h
+++ b/myserver/include/connections_scheduler/connections_scheduler.h
@@ -109,7 +109,8 @@ public:
 
   void newData (short event, SocketHandle handle);
 
-private:
+  Semaphore *getReadySemaphore () {return readySemaphore;}
+protected:
   Server* server;
   void addWaitingConnectionImpl (ConnectionPtr, int lock);
   void addReadyConnectionImpl (ConnectionPtr);
diff --git a/myserver/include/server/server.h b/myserver/include/server/server.h
index 43c8c35..1663545 100644
--- a/myserver/include/server/server.h
+++ b/myserver/include/server/server.h
@@ -110,7 +110,8 @@ public:
   u_long getTimeout ();
   const char *getAddresses ();
   const char *getPath ();
-  u_long getNumThreads ();
+  void getThreadsNumberInformation (u_long *num, u_long *max = NULL,
+                                    u_long *staticThreads = NULL);
 
   NodeTree<string>* getNodeTree (string& key)
   {
diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index 798558f..fed80e5 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -168,6 +168,9 @@ static void listenerHandler (int fd, short event, void *arg)
   ConnectionsScheduler::ListenerArg* s
     = (ConnectionsScheduler::ListenerArg*) arg;
 
+  if (event == EV_TIMEOUT)
+    s->scheduler->getReadySemaphore ()->unlock ();
+
   if (event == EV_READ)
     {
       MYSERVER_SOCKADDRIN asockIn;
@@ -575,14 +578,15 @@ ConnectionPtr ConnectionsScheduler::getConnection ()
 void ConnectionsScheduler::release ()
 {
   u_long nbw;
-  u_long max = 0;
+  u_long threads = 0;
   releasing = true;
   dispatcherArg.terminate = true;
 
   if (server)
-    max = server->getNumThreads () * 2;
+    server->getThreadsNumberInformation (&threads);
+  threads *= 2;
 
-  for (u_long i = 0; i < max; i++)
+  for (u_long i = 0; i < threads; i++)
     readySemaphore->unlock ();
 
   eventsSocketMutex.lock ();
diff --git a/myserver/src/server/clients_thread.cpp 
b/myserver/src/server/clients_thread.cpp
index 61707ae..15e8a60 100644
--- a/myserver/src/server/clients_thread.cpp
+++ b/myserver/src/server/clients_thread.cpp
@@ -147,22 +147,19 @@ DEFINE_THREAD (clients_thread, pParam)
       int ret;
       try
         {
-          /* If the thread can be destroyed don't use it.  */
-          if ((!ct->isStatic ()) && ct->isToDestroy ())
-            {
-              Thread::wait (1000);
-              break;
-            }
-
           ret = ct->controlConnections ();
           ct->server->increaseFreeThread ();
           ct->busy = false;
 
-          /*
-            The thread served the connection, so update the timeout value.
-           */
+          /* The thread served the connection, so update the timeout value.  */
           if (ret != 1)
             ct->setTimeout (getTicks ());
+
+          if ((!ct->isStatic ()) && ct->isToDestroy ())
+            {
+              Thread::wait (MYSERVER_SEC (60));
+              break;
+            }
         }
       catch (bad_alloc &ba)
         {
@@ -257,7 +254,7 @@ int ClientsThread::controlConnections ()
 
   server->decreaseFreeThread ();
 
-  if (!c)
+  if (! c)
     return 1;
 
   busy = true;
@@ -284,12 +281,12 @@ int ClientsThread::controlConnections ()
       return 0;
     }
 
-  if (getTicks () - c->getTimeout () > 5000)
+  if (getTicks () - c->getTimeout () > MYSERVER_SEC (5))
     c->setnTries (0);
 
   if (dataRead)
-    memcpy ((char*)buffer.getBuffer (), c->getConnectionBuffer ()->getBuffer 
(),
-            dataRead);
+    memcpy ((char*) buffer.getBuffer (),
+            c->getConnectionBuffer ()->getBuffer (), dataRead);
 
   c->setActiveThread (this);
   try
@@ -326,7 +323,6 @@ int ClientsThread::controlConnections ()
   if (retcode == DELETE_CONNECTION)
     {
       server->deleteConnection (c);
-      return 0;
     }
   /* Keep the connection.  */
   else if (retcode == KEEP_CONNECTION)
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index 9833ea7..9683c59 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -443,10 +443,9 @@ void Server::mainLoop ()
    */
   while (!endServer)
     {
-      Thread::wait (1000000);
+      Thread::wait (MYSERVER_SEC (1));
 
-      /* Check threads.  */
-      if (purgeThreadsCounter++ >= 10)
+      if (purgeThreadsCounter++ >= 120)
         {
           purgeThreadsCounter = 0;
           purgeThreads ();
@@ -462,8 +461,8 @@ void Server::mainLoop ()
             FilesUtility::getLastModTime (mimeConfigurationFile.c_str ());
 
           /* If a configuration file was modified reboot the server. */
-          if (((mainConfTimeNow != -1) && (hostsConfTimeNow != -1)  &&
-               (mimeConfNow != -1)) || toReboot)
+          if (((mainConfTimeNow != -1) && (hostsConfTimeNow != -1)
+               && (mimeConfNow != -1)) || toReboot)
             {
               if ( (mainConfTimeNow  != mainConfTime) || toReboot)
                 {
@@ -596,7 +595,7 @@ int Server::purgeThreads ()
   u_long ticks = getTicks ();
   u_long destroyed = 0;
 
-  purgeThreadsThreshold = std::min (purgeThreadsThreshold << 1,
+  purgeThreadsThreshold = std::min (purgeThreadsThreshold * 3 / 2,
                                     nMaxThreads);
   threadsMutex->lock ();
   for (list<ClientsThread*>::iterator it = threads.begin ();
@@ -610,11 +609,8 @@ int Server::purgeThreads ()
           list<ClientsThread*>::iterator next = it;
           next++;
 
-          thread->join ();
           threads.erase (it);
           delete thread;
-
-          destroyed++;
           it = next;
         }
       else if (thread->isToDestroy ())
@@ -622,14 +618,17 @@ int Server::purgeThreads ()
           if (destroyed < purgeThreadsThreshold)
             thread->stop ();
 
+          destroyed++;
           it++;
         }
       else
         {
-          if (!thread->isStatic ())
-            if (ticks - thread->getTimeout () > MYSERVER_SEC (15))
-              thread->setToDestroy (1);
-
+          if (! thread->isStatic ())
+            if (ticks - thread->getTimeout () > MYSERVER_SEC (20))
+              {
+                thread->setToDestroy (1);
+                destroyed++;
+              }
           it++;
         }
     }
@@ -1315,15 +1314,23 @@ const char *Server::getServerName ()
 }
 
 /*!
-  Gets the number of threads.
- */
-u_long Server::getNumThreads ()
+  Get Information on the number of threads.
+  \param num if not NULL will contain the number of active threads.
+  \param max if not NULL will contain the maximum number of threads.
+  \param staticThreads if not NULL will contain the maximum number of always
+  active threads.
+*/
+void Server::getThreadsNumberInformation (u_long *num, u_long *max,
+                                          u_long *staticThreads)
 {
-  u_long ret;
-  threadsMutex->lock ();
-  ret = threads.size ();
-  threadsMutex->unlock ();
-  return ret;
+  if (num)
+    *num = threads.size ();
+
+  if (max)
+    *max = nMaxThreads;
+
+  if (staticThreads)
+    *staticThreads = nStaticThreads;
 }
 
 /*!
@@ -1588,7 +1595,6 @@ int Server::addThread (bool staticThread)
   newThread = new ClientsThread (this);
 
   handlers = getHandlers (msg);
-
   if (handlers)
     {
       for (size_t i = 0; i < handlers->size (); i++)



commit a35680902adf62510957db1294de7aacc210ee1c
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun May 16 21:57:39 2010 +0200

    Change precision of getTicks to microseconds.

diff --git a/myserver/src/base/utility.cpp b/myserver/src/base/utility.cpp
index 017d6d3..3bc47be 100644
--- a/myserver/src/base/utility.cpp
+++ b/myserver/src/base/utility.cpp
@@ -195,20 +195,16 @@ int endPrintError ()
 }
 
 /*!
-  Return the ticks count in milliseconds.
+  Return the ticks count in microseconds.
   Return 0 on errors.
  */
 u_long getTicks ()
 {
-#ifdef WIN32
-  return GetTickCount ();
-#else
   struct timeval tval;
   int ret = checked::gettimeofday (&tval, 0);
   if (ret == -1)
     return 0;
-  return  (tval.tv_sec * 1000) + (tval.tv_usec / 1000);
-#endif
+  return  (tval.tv_sec * 1000000) + tval.tv_usec;
 }
 
 /*!

-----------------------------------------------------------------------

Summary of changes:
 .../connections_scheduler/connections_scheduler.h  |    3 +-
 myserver/include/server/server.h                   |    3 +-
 myserver/src/base/utility.cpp                      |    8 +--
 .../connections_scheduler.cpp                      |   10 +++-
 myserver/src/server/clients_thread.cpp             |   26 ++++------
 myserver/src/server/server.cpp                     |   50 +++++++++++---------
 6 files changed, 52 insertions(+), 48 deletions(-)


hooks/post-receive
-- 
GNU MyServer



reply via email to

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