/head: changeset 93
Optimized acquireconnection to try to return the last connection owned by this thread
This commit is contained in:
parent
120076256f
commit
8029c6a25e
@ -8,8 +8,9 @@ offlineimap (2.0.8) unstable; urgency=low
|
|||||||
bug.
|
bug.
|
||||||
* Modified Maildir folder to unlink messages with T flag in
|
* Modified Maildir folder to unlink messages with T flag in
|
||||||
cachemessagelist()
|
cachemessagelist()
|
||||||
|
* My own box now syncs in 3 seconds.
|
||||||
|
|
||||||
-- John Goerzen <jgoerzen@complete.org> Wed, 10 Jul 2002 12:29:30 -0500
|
-- John Goerzen <jgoerzen@complete.org> Tue, 9 Jul 2002 23:29:30 -0500
|
||||||
|
|
||||||
offlineimap (2.0.7) unstable; urgency=low
|
offlineimap (2.0.7) unstable; urgency=low
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
from offlineimap import imaplib, imaputil, threadutil
|
from offlineimap import imaplib, imaputil, threadutil
|
||||||
from threading import *
|
from threading import *
|
||||||
|
import thread
|
||||||
|
|
||||||
class UsefulIMAPMixIn:
|
class UsefulIMAPMixIn:
|
||||||
def getstate(self):
|
def getstate(self):
|
||||||
@ -64,6 +65,7 @@ class IMAPServer:
|
|||||||
self.maxconnections = maxconnections
|
self.maxconnections = maxconnections
|
||||||
self.availableconnections = []
|
self.availableconnections = []
|
||||||
self.assignedconnections = []
|
self.assignedconnections = []
|
||||||
|
self.lastowner = {}
|
||||||
self.semaphore = BoundedSemaphore(self.maxconnections)
|
self.semaphore = BoundedSemaphore(self.maxconnections)
|
||||||
self.connectionlock = Lock()
|
self.connectionlock = Lock()
|
||||||
self.reference = reference
|
self.reference = reference
|
||||||
@ -97,9 +99,22 @@ class IMAPServer:
|
|||||||
imapobj = None
|
imapobj = None
|
||||||
|
|
||||||
if len(self.availableconnections): # One is available.
|
if len(self.availableconnections): # One is available.
|
||||||
imapobj = self.availableconnections[0]
|
# Try to find one that previously belonged to this thread
|
||||||
|
# as an optimization. Start from the back since that's where
|
||||||
|
# they're popped on.
|
||||||
|
threadid = thread.get_ident()
|
||||||
|
imapobj = None
|
||||||
|
for i in range(len(self.availableconnections) - 1, -1, -1):
|
||||||
|
tryobj = self.availableconnections[i]
|
||||||
|
if self.lastowner[tryobj] == threadid:
|
||||||
|
imapobj = tryobj
|
||||||
|
del(self.availableconnections[i])
|
||||||
|
break
|
||||||
|
if not imapobj:
|
||||||
|
imapobj = self.availableconnections[0]
|
||||||
|
del(self.availableconnections[0])
|
||||||
self.assignedconnections.append(imapobj)
|
self.assignedconnections.append(imapobj)
|
||||||
del(self.availableconnections[0])
|
self.lastowner[imapobj] = thread.get_ident()
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
return imapobj
|
return imapobj
|
||||||
|
|
||||||
@ -124,6 +139,7 @@ class IMAPServer:
|
|||||||
|
|
||||||
self.connectionlock.acquire()
|
self.connectionlock.acquire()
|
||||||
self.assignedconnections.append(imapobj)
|
self.assignedconnections.append(imapobj)
|
||||||
|
self.lastowner[imapobj] = thread.get_ident()
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
return imapobj
|
return imapobj
|
||||||
|
|
||||||
@ -146,6 +162,7 @@ class IMAPServer:
|
|||||||
imapobj.logout()
|
imapobj.logout()
|
||||||
self.assignedconnections = []
|
self.assignedconnections = []
|
||||||
self.availableconnections = []
|
self.availableconnections = []
|
||||||
|
self.lastowner = {}
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
|
|
||||||
def keepalive(self, timeout, event):
|
def keepalive(self, timeout, event):
|
||||||
@ -168,14 +185,14 @@ class IMAPServer:
|
|||||||
for i in range(numconnections):
|
for i in range(numconnections):
|
||||||
imapobj = self.acquireconnection()
|
imapobj = self.acquireconnection()
|
||||||
imapobjs.append(imapobj)
|
imapobjs.append(imapobj)
|
||||||
thread = threadutil.ExitNotifyThread(target = imapobj.noop)
|
thr = threadutil.ExitNotifyThread(target = imapobj.noop)
|
||||||
thread.setDaemon(1)
|
thr.setDaemon(1)
|
||||||
thread.start()
|
thr.start()
|
||||||
threads.append(thread)
|
threads.append(thr)
|
||||||
|
|
||||||
for thread in threads:
|
for thr in threads:
|
||||||
# Make sure all the commands have completed.
|
# Make sure all the commands have completed.
|
||||||
thread.join()
|
thr.join()
|
||||||
|
|
||||||
for imapobj in imapobjs:
|
for imapobj in imapobjs:
|
||||||
self.releaseconnection(imapobj)
|
self.releaseconnection(imapobj)
|
||||||
|
Loading…
Reference in New Issue
Block a user