forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

High CPU and BIO from telnetlib

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Mon Dec 09, 2013 10:55 pm    Post subject: High CPU and BIO from telnetlib Reply with quote

Hi.
For some reason this piece of code consumes close to 1 CPU sec and
a bit over 25.000 buff I/O for each loop in the while-loop:
Code:

$ python

import sys
import telnetlib

tn = telnetlib.Telnet('10.32.137.39', 3008)

while 1:
  print tn.read_until(chr(3), 5)

The code simply connects to a terminal server port (Lantronics ETS8P, if it matters)
and waits for data. It returns either when it sees an ETX (End Of Text, hex 03) or after a 5 sec timeout.
I can not see why this quite simply code should consume that much resources.

Hm, it is only when the read is terminated by a timeout that it does that.
If I write to the port (the serial ports on the term.server are looped in pairs so that
I can feed testdata to our apps that read barcode scanners and other hardware) before
the timeout, it prints the data and loops into another read_until with no measurable CPU...

So it is the timeout itself that is the problem here...
OK, a workaround is to simply use a longer timeout...

Weird, anyway...

Jan-Erik.
Back to top
View user's profile Send private message
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Tue Dec 10, 2013 11:02 am    Post subject: Reply with quote

It seem that the problem is the routine poll in the select module.
Your can try the following code:
Code:
$ python

import sys
import select
del select.poll
import telnetlib

tn = telnetlib.Telnet('10.32.137.39', 3008)

while 1:
  print tn.read_until(chr(3), 5)


This seem to solve the high CPU and buff I/O consumption.
JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Tue Dec 10, 2013 11:03 pm    Post subject: Reply with quote

Yes, the two extra lines in the import parts "solved" that issue.
That is now included in my test-scripts.
Jan-Erik.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group