Is PythonService Slow, Or, Is It The Code?
John Abel
johnfabel at btinternet.com
Wed May 21 13:47:03 EDT 2003
Using medusa, I've written a simple FTP server to run on my Win2000
machine. I have two versions, a Win32 service, and the other is
launched from the command line. I've noticed, that the Win32 service is
drastically slower than the command line version. As a test, I ftp'ed a
148MB file from one machine to another (connected via a twisted cable,
at 10Mbps). Using the service, the file transfered at 31kb/sec; with
the cli version, it transfered at 549kb/sec.
Has anyone any ideas as to the huge performace difference?
Thanks
John
Here's the code for the Win32 service. The cli version, is a normal
medusa-based FTP server, using the same Win32 Auth code as the service.
Win32 Service:
def __init__( self, args ):
win32serviceutil.ServiceFramework.__init__( self, args )
self.hWaitStop = win32event.CreateEvent( None, 0, 0, None )
def SvcStop( self ):
self.ReportServiceStatus( win32service.SERVICE_STOP_PENDING )
win32event.SetEvent( self.hWaitStop )
def SvcDoRun( self ):
logFile = logger.file_logger(
"D:\\Scripts\\LogFiles\\FTP-Xfer.log" )
ftpServ = ftp_server.ftp_server( Win32Authorizer(),
port=21,
logger_object=logFile )
timeout=5
map = asyncore.socket_map
while map:
retCode = win32event.WaitForSingleObject( self.hWaitStop, 500 )
if retCode == win32event.WAIT_OBJECT_0:
break
asyncore.poll(timeout, map)
class Win32Authorizer:
def authorize (self, channel, userName, passWord):
self.AdjustPrivilege( ntsecuritycon.SE_CHANGE_NOTIFY_NAME )
self.AdjustPrivilege( ntsecuritycon.SE_ASSIGNPRIMARYTOKEN_NAME )
self.AdjustPrivilege( ntsecuritycon.SE_TCB_NAME )
try:
logonHandle = win32security.LogonUser( userName,
None,
passWord,
win32con.LOGON32_LOGON_INTERACTIVE,
win32con.LOGON32_PROVIDER_DEFAULT )
except pywintypes.error, ErrorMsg:
return 0, ErrorMsg[ 2 ], None
userInfo = win32net.NetUserGetInfo( None, userName, 1 )
return 1, 'Login successful', filesys.os_filesystem( userInfo[
'home_dir' ] )
def AdjustPrivilege( self, priv ):
flags = ntsecuritycon.TOKEN_ADJUST_PRIVILEGES |
ntsecuritycon.TOKEN_QUERY
htoken =
win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags)
id = win32security.LookupPrivilegeValue(None, priv)
newPrivileges = [(id, ntsecuritycon.SE_PRIVILEGE_ENABLED)]
win32security.AdjustTokenPrivileges(htoken, 0, newPrivileges)
More information about the Python-list
mailing list