public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Search Repo:
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
ApplicationPool.get() now times out based on time instead of number of 
attempts.
Hongli Lai (Phusion) (author)
Thu May 15 16:40:53 -0700 2008
commit  d0d8a84ca15123cbcd73319c7b6c78f31ee06f4e
tree    896bc55404527c1176f566c6927c7fa3b20a2468
parent  542ea8c426414bea1cf583c189194c56688a1712
...
144
145
146
147
 
 
 
148
 
149
150
151
152
153
154
...
167
168
169
170
171
172
173
174
175
 
176
177
178
179
 
 
 
180
181
182
183
184
185
...
144
145
146
 
147
148
149
150
151
152
153
154
155
156
157
...
170
171
172
 
173
174
175
176
 
177
178
179
180
 
181
182
183
184
185
 
186
187
188
0
@@ -144,8 +144,11 @@
0
 
0
 function get(app_root):
0
   MAX_ATTEMPTS = 10
0
- attempt = 1
0
+ TIMEOUT = 5000000 # in microseconds
0
+ attempt = 0
0
+ total_sleep_time = 0
0
   while (true):
0
+ attempt++
0
     lock.synchronize:
0
       container, list = spawn_or_use_existing(app_root)
0
       if (container != null):
0
0
0
0
@@ -167,19 +170,19 @@
0
             app_instance_count.remove(app_root)
0
             count--
0
             active--
0
- attempt++
0
     if (container == null):
0
       # Unable to spawn or connect to an application right
0
       # now. Try again later, unless we've already tried too
0
       # many times.
0
- if (attempt == MAX_ATTEMPTS):
0
+ if (total_sleep_time > TIMEOUT):
0
         raise exception
0
       waiting_lock.synchronize:
0
         waiting++
0
- usleep(attempt * 2000)
0
+ sleep_time = attempt * 2000
0
+ total_sleep_time += sleep_time
0
+ usleep(total_sleep_time)
0
       waiting_lock.synchronize:
0
         waiting--
0
- attempt++
0
 
0
 
0
 # Returns a pair of [AppContainer, list<AppContainer>] that matches the
...
330
331
332
333
 
334
335
336
...
330
331
332
 
333
334
335
336
0
@@ -330,7 +330,7 @@
0
         } else {
0
           throw SpawnException(args[1]);
0
         }
0
- } else if (args[0] == "BusyExeption") {
0
+ } else if (args[0] == "BusyException") {
0
         throw BusyException(args[1]);
0
       } else if (args[0] == "IOException") {
0
         throw IOException(args[1]);
...
93
94
95
 
96
97
98
99
100
...
519
520
521
 
522
523
 
 
524
 
 
525
526
527
528
529
...
560
561
562
563
564
565
566
567
568
569
570
 
571
572
573
574
575
576
577
 
 
 
578
579
580
...
93
94
95
96
97
98
99
100
101
...
520
521
522
523
524
 
525
526
527
528
529
530
531
532
533
534
...
565
566
567
 
568
569
570
571
572
573
 
574
575
576
577
578
579
580
 
581
582
583
584
585
586
0
@@ -93,6 +93,7 @@
0
   static const int DEFAULT_MAX_INSTANCES_PER_APP = 0;
0
   static const int CLEANER_THREAD_STACK_SIZE = 1024 * 128;
0
   static const unsigned int MAX_GET_ATTEMPTS = 10;
0
+ static const unsigned int GET_TIMEOUT = 5000000; // In microseconds.
0
 
0
   friend class ApplicationPoolServer;
0
   struct AppContainer;
0
0
0
@@ -519,9 +520,13 @@
0
     const string &spawnMethod = "smart"
0
   ) {
0
     unsigned int attempt;
0
+ unsigned int totalSleepTime;
0
     
0
- attempt = 1;
0
+ attempt = 0;
0
+ totalSleepTime = 0;
0
     while (true) {
0
+ attempt++;
0
+
0
       mutex::scoped_lock l(lock);
0
       pair<AppContainerPtr, AppContainerList *> p(
0
         spawnOrUseExisting(l, appRoot, lowerPrivilege, lowestUser,
0
0
0
@@ -560,21 +565,22 @@
0
             appInstanceCount.erase(appRoot);
0
             count--;
0
             active--;
0
- attempt++;
0
             P_ASSERT(verifyState(), Application::SessionPtr(), "State is valid.");
0
           }
0
         }
0
       }
0
       if (container == NULL) {
0
         l.unlock();
0
- if (attempt == MAX_GET_ATTEMPTS) {
0
+ if (totalSleepTime > GET_TIMEOUT) {
0
           throw BusyException("Cannot satisfy get() request.");
0
         }
0
         {
0
           mutex::scoped_lock wl(waitingLock);
0
           waiting++;
0
         }
0
- usleep(attempt * 20000);
0
+ unsigned int sleepTime = attempt * 10000;
0
+ totalSleepTime += sleepTime;
0
+ usleep(sleepTime);
0
         {
0
           mutex::scoped_lock wl(waitingLock);
0
           waiting--;

Comments

    No one has commented yet.