Re: reducing perl cpu usage

2013-01-14 Thread David Precious
On Mon, 14 Jan 2013 11:22:18 +0700
budi pearl budipe...@gmail.com wrote:

 Is there any way to reduce the processor usage by perl?
 I am trying to use nice -19 but proc usage is still 100%

Depends what your code is doing.  If you're doing a continuous loop or
something, yes, you'll eat up CPU.

Devel::NYTProf can be awesome to see where your code is spending most
of its time, so you know where to focus.


-- 
David Precious (bigpresh) dav...@preshweb.co.uk
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook
www.preshweb.co.uk/cpanwww.preshweb.co.uk/github



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: reducing perl cpu usage

2013-01-14 Thread Shawn H Corey
On Mon, 14 Jan 2013 11:22:18 +0700
budi pearl budipe...@gmail.com wrote:

 Is there any way to reduce the processor usage by perl?
 I am trying to use nice -19 but proc usage is still 100%

According to the man page, you should try: nice 19

See http://linux.about.com/library/cmd/blcmdl1_nice.htm


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Line-oriented socket I/O using select()

2013-01-14 Thread Bob McConnell
 From: Vic Sage
 
 I'm writing a multiplexed TCP-based server that reads \n-terminated
 strings from clients and does something with them.  Since this is one process
 with multiple client connections, it uses select() (or, actually, can_read 
 from
 IO::Select) to block until data has arrived from any client.
 
 It's my understanding that TCP does not preserve message boundaries.
 That is, if a client writes:
 
 $sock-autoflush(1);
 print $sock abel\n;
 print $sock baker\n;
 print $sock charlie\n;
 
 ... there are no guarantees about what will be returned from the server's
 system buffer by sysread() when select() pops.  It could be a, or abel\n,
 or abel\nbak, etc.
 
 What I *want* is to block until an entire \n-terminated string [can that be
 referred to as a line?]  can be retrieved from one of my clients.  I'm sure 
 I
 could work out the logic to maintain application-level buffers, but I suspect 
 I
 would merely be reinventing the wheel, one bug at a time :-).   What does
 the experienced Perl programmer - or socket-level programmer in general -
 do in this situation?

TCP is a stream oriented protocol. As you noted it does not make any guarantee 
about fragmenting or appending data because it just doesn't care what it 
transports. It simply guarantees the octets will arrive in the same order they 
were sent. There are no assumptions nor restrictions on what those octets 
represent.

Therefore, Perl cannot do what you asked for either. It is necessary for your 
application to keep track of the message boundaries and manage multiple and/or 
incomplete messages from a single read.

Having dealt with this issue many times over the past 20 years or so, I have 
developed a couple of approaches. The first is a two layer version that reads 
the incoming data from the socket and queues it into a circular buffer. The 
next layer extracts individual messages from the buffer and hands them off to a 
parser, or whatever is needed next. The size of the buffer is dependent on a 
lot of variables which vary by application and protocol. The possibility of 
overflow is too much of a risk in some cases. Another approach is message 
queues where the incoming octets are moved into a buffer until the boundary 
marker arrives. That buffer is sent to a message queue and the next buffer is 
opened. I often use XINU style message queues for this approach. The risk here 
is the possibility of running out of buffers.

There may be other options to simplify this. One popular variation is to 
precede each message with a two byte length value. Normally this will be a 16 
bit integer in network byte order. You read the two bytes, then do another read 
for the number of bytes indicated by them. You still have to manage fragments, 
but no longer need to deal directly with multiples.

Bob McConnell


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: character setts in a regexp

2013-01-14 Thread John SJ Anderson
On Fri, Jan 11, 2013 at 2:01 PM, Christer Palm b...@bredband.net wrote:
 Do you have suggestions on this character issue? Is it possible to determine 
 the character set of a text efficiently? Is it other ways to solve the 
 problem?

As far as other ways to solve the problem, my suggestion would be to
not use regexps to parse XML, use an XML parser. For example,
something like https://metacpan.org/module/XML::Feed .

chrs,
john.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Hi

2013-01-14 Thread Lou Pereira
OK, So I performed you step 3 again last Thursday, but I am still receiving
e-mails??? Any more suggestions?


Regards;

Lou Pereira
C: (973) 670-6821
mailto:louis.pere...@ptalc.com

-Original Message-
From: Kristin Nielsen [mailto:justkris...@gmail.com] On Behalf Of Kristin
Nielsen
Sent: Friday, January 11, 2013 9:14 AM
To: Lou Pereira
Cc: beginners@perl.org
Subject: Re: Hi

If you do not give data for troubleshooting, there is no good way to help.
See step 3:

3. If you are not unsubscribed, please add in your requests for further help
(as simply saying it doesn't work does not help people troubleshoot, as we
all know too well):
   a. the email - including headers - that you sent to
beginners-unsubscr...@perl.org
   b. any replies you may have rec'd from the list server, especially if
they contain denials or errors.

I am, c.
Kristin

Sent while galavanting.

On Jan 11, 2013, at 3:23 AM, Lou Pereira louis.pere...@ptalc.com wrote:

 For the past year I have exhausted all options of e-mail format to opt
out,
 including your recommendations to no avail.   I must say that over 10
years
 I have been involved with different e-mail lists and tech groups, but 
 never had such as poor service as this group.  Any other ideas would 
 be appreciated?
 
 
 Regards;
 
 Lou Pereira
 C: (973) 670-6821
 mailto:louis.pere...@ptalc.com
 
 
 -Original Message-
 From: Kristin Nielsen [mailto:kris...@justkristin.com]
 Sent: Thursday, January 10, 2013 6:50 PM
 To: Lou Pereira
 Cc: beginners@perl.org
 Subject: Re: Hi
 
 Lou -
 
 Klamerus' frustration is not completely unwarranted. I answered that 
 question in my reply to the list - did you read it? If not, there are 
 three steps to take - fewer if you are successful.
 
 1. Start an email from the account with which you subscribed to the list.
 You MUST send your unsubscribe request from the email address by which 
 list mail is being rec'd.
 2. Send a simple blank email from the account mentioned in step #1 to 
 beginners-unsubscr...@perl.org 3. If you are not unsubscribed, please 
 add in your requests for further help (as simply saying it doesn't 
 work does not help people troubleshoot, as we all know too well):
a. the email - including headers - that you sent to 
 beginners-unsubscr...@perl.org
b. any replies you may have rec'd from the list server, especially 
 if they contain denials or errors.
 
 There you go.
 
 I am, c.,
 
 Kristin
 
 P. S. I take quite to heart the belittling attitude found on so many 
 tech lists. Bad attitude doesn't work from either direction, and yes, 
 delivery matters. This is supposed to be a cooperative educational 
 community, is it not? Sure, we should all RTFM, but some of us who 
 have been forced to learn-or-get-laid-off simply lack the formal 
 training to know which term to use in our search, or even to know 
 which PERLDOC to read, have been shamed into silence by cruel 
 responses.  I am far beyond that now, but I remember it well. 
 Furthermore, this list contains quite a few for whom English is not a 
 first language. I am grateful to everyone here for being on the list 
 and helping those who come to it for assistance. We all get frustrated 
 with simplistic or repetitive questions, and people who don't even try 
 should be told to try first, but very little besides a bully's ego is
helped by mean replies. No?
 
 Thanks again, all of you, really.
 
 On Jan 10, 2013, at 3:36 PM, Lou Pereira louis.pere...@ptalc.com
wrote:
 
 I beg to differ regarding your comment.  I have been trying to be 
 removed from this list for over a year to no avail.  So, all 
 knowledge one, how do we remove ourselves from this mail list?
 
 
 
 -Original Message-
 From: klamerus [mailto:klame...@earthlink.net]
 Sent: Thursday, January 10, 2013 4:10 PM
 To: 'bhanu chaitanya abbaraju'; beginners@perl.org
 Subject: RE: Hi
 
 Since you clearly don't know how mailing lists work I'm afraid that's 
 not possible.
 
 -Original Message-
 From: bhanu chaitanya abbaraju [mailto:bhanu.cha...@gmail.com]
 Sent: Thursday, January 10, 2013 2:04 PM
 To: beginners@perl.org
 Subject: Hi
 
 Please help me how can I stop perl emails
 
 --
 A.Bhanuchaitanya
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: reducing perl cpu usage

2013-01-14 Thread Jim Gibson

On Jan 13, 2013, at 8:22 PM, budi pearl wrote:

 Hi All,
 
 Is there any way to reduce the processor usage by perl?
 I am trying to use nice -19 but proc usage is still 100%
 
 Tasks: 189 total,   2 running, 187 sleeping,   0 stopped,   0 zombie
 Cpu(s):  0.0%us,  0.5%sy, 26.0%ni, 73.5%id,  0.0%wa,  0.0%hi,  0.0%si,
 0.0%st
 Mem:   4042684k total,  3463524k used,   579160k free,   249812k buffers
 Swap:  4095992k total,0k used,  4095992k free,  2542732k cached
 
  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND
 24652 budi   39  19  186m  97m 1980 R 100.0  2.5   3:03.78 route_processor
 24304 budi   15   0 88112 1768 1036 S  1.8  0.0   0:00.08 sshd
1 root  15   0 10364  692  580 S  0.0  0.0   0:06.62 init
2 root  RT  -5 000 S  0.0  0.0   0:19.63 migration/0

Why do you want to reduce your CPU usage?

That may seem like a silly question (who wouldn't want to reduce their CPU 
usage), but the answer to that question will affect the suggestions you will 
get. Is your program taking too long to run? Is it slowing down other programs? 
Are you on a shared system and the other users complaining about your program 
being a CPU hog?

You should not be concerned just because your program is taking 100% of a CPU. 
That is as it should be. If there are no other significant processes running, 
your program will utilize 100% of the available CPU unless it is blocked 
waiting for system resources, such as input or output. Changing the priority of 
your Perl program will not affect that. You want your program running as much 
as possible so that it completes its task in the minimum amount of time.

Only if your Perl program is competing for CPU or other resources will changing 
the priority have any effect. If your program is slowing down other programs, 
then changing the priority is the way to go (but do read 'man nice' and use a 
positive number). If that doesn't work, then you can try limiting the resources 
your program uses. For CPU usage, you can sprinkle sleep(1) statements in your 
program. However, that will result in your program taking longer to complete 
its task and may result in wasted CPU cycles. If your program has more work to 
do, and no other program wants to use the CPU, then you really want the CPU to 
be busy executing your program.

The best way to reduce your program's CPU usage program is to make your program 
more efficient. You can either do the same amount of work more efficiently, or 
do less work by improving your algorithm.

However, we really need to know what problem you are trying to solve to better 
advise you.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: character setts in a regexp

2013-01-14 Thread Charles DeRykus
On Sat, Jan 12, 2013 at 12:56 PM, Charles DeRykus dery...@gmail.com wrote:
 On Fri, Jan 11, 2013 at 2:01 PM, Christer Palm b...@bredband.net wrote:
 Hi!

 I have a perl script that parses RSS streams from different news sources and 
 experience problems with national characters in a regexp function used for 
 matching a keyword list with the RSS data.

 Everything works fine with a simple regexp for plain english i.e. words 
 containing the letters A-Z, a-z, 0-9.

 if ( $description =~ m/\b$key/i ) {….}

 Keywords or RSS data with national characters don’t work at all. I’m not 
 really surprised this was expected as character sets used in the different 
 RSS streams are outside my control.

 I am have the ”use utf8;” function activated but I’m not really sure if it 
 is needed. I can’t see any difference used or not.

 If a convert all the national characters used in the keyword list to html 
 type ”aring” and so on. Changes every occurrence of octal, unicode 
 characters used i.e. decimal and hex to html type in the RSS data in a 
 character parser everything works fine but takes time that I don’t what to 
 avoid.

 Do you have suggestions on this character issue? Is it possible to determine 
 the character set of a text efficiently? Is it other ways to solve the 
 problem?

...

 #!/usr/bin/perl
 use strict;
 use warnings;

 binmode(STDOUT, :utf8);
 $cosa = my \x{263a};
 print cosa=$cosa\n;

 print found smiley at \\b\n if $cosa =~ /\b\x{263a}/;
 print found smiley (no \\b)  if $cosa =~ /\x{263a}/;

 The output:
 cosa=my ☺
 found smiley (no \b)


From: http://www.unicode.org/reports/tr18/#Simple_Word_Boundaries
---
Most regular expression engines allow a test for word boundaries (such
as by \b in Perl). They generally use a very simple mechanism for
determining word boundaries: one example of that would be having word
boundaries between any pair of characters where one is a
word_character and the other is not, or at the start and end of a
string. This is not adequate for Unicode regular expressions.
-

Based on the above, Perl's \b semantics appear to be not adequate
for Unicode regular expressions since, it doesn't address extended
code points of Unicode, only values in the alphanumeric range and
underscore.

So, you may possibly want to try a preceding space to delimit the
keyword

print match if my \x{263a}=~ / \x{263a}/;   # matches!
#print match if my \b\x{263a} =~ /\b\x{263a/;   # would not match

-- 
Charles DeRykus

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Hi

2013-01-14 Thread Torqued


Regards... /omps

On 14-Jan-2013, at 11:12 PM, Lou Pereira louis.pere...@ptalc.com wrote:

 OK, So I performed you step 3 again last Thursday, but I am still receiving
 e-mails??? Any more suggestions?
 
May be the group doesn't want you to leave. ;)

 Regards;
 
 Lou Pereira
 C: (973) 670-6821
 mailto:louis.pere...@ptalc.com
 
 -Original Message-
 From: Kristin Nielsen [mailto:justkris...@gmail.com] On Behalf Of Kristin
 Nielsen
 Sent: Friday, January 11, 2013 9:14 AM
 To: Lou Pereira
 Cc: beginners@perl.org
 Subject: Re: Hi
 
 If you do not give data for troubleshooting, there is no good way to help.
 See step 3:
 
 3. If you are not unsubscribed, please add in your requests for further help
 (as simply saying it doesn't work does not help people troubleshoot, as we
 all know too well):
   a. the email - including headers - that you sent to
 beginners-unsubscr...@perl.org
   b. any replies you may have rec'd from the list server, especially if
 they contain denials or errors.
 
 I am, c.
 Kristin
 
 Sent while galavanting.
 
 On Jan 11, 2013, at 3:23 AM, Lou Pereira louis.pere...@ptalc.com wrote:
 
 For the past year I have exhausted all options of e-mail format to opt
 out,
 including your recommendations to no avail.   I must say that over 10
 years
 I have been involved with different e-mail lists and tech groups, but 
 never had such as poor service as this group.  Any other ideas would 
 be appreciated?
 
 
 Regards;
 
 Lou Pereira
 C: (973) 670-6821
 mailto:louis.pere...@ptalc.com
 
 
 -Original Message-
 From: Kristin Nielsen [mailto:kris...@justkristin.com]
 Sent: Thursday, January 10, 2013 6:50 PM
 To: Lou Pereira
 Cc: beginners@perl.org
 Subject: Re: Hi
 
 Lou -
 
 Klamerus' frustration is not completely unwarranted. I answered that 
 question in my reply to the list - did you read it? If not, there are 
 three steps to take - fewer if you are successful.
 
 1. Start an email from the account with which you subscribed to the list.
 You MUST send your unsubscribe request from the email address by which 
 list mail is being rec'd.
 2. Send a simple blank email from the account mentioned in step #1 to 
 beginners-unsubscr...@perl.org 3. If you are not unsubscribed, please 
 add in your requests for further help (as simply saying it doesn't 
 work does not help people troubleshoot, as we all know too well):
   a. the email - including headers - that you sent to 
 beginners-unsubscr...@perl.org
   b. any replies you may have rec'd from the list server, especially 
 if they contain denials or errors.
 
 There you go.
 
 I am, c.,
 
 Kristin
 
 P. S. I take quite to heart the belittling attitude found on so many 
 tech lists. Bad attitude doesn't work from either direction, and yes, 
 delivery matters. This is supposed to be a cooperative educational 
 community, is it not? Sure, we should all RTFM, but some of us who 
 have been forced to learn-or-get-laid-off simply lack the formal 
 training to know which term to use in our search, or even to know 
 which PERLDOC to read, have been shamed into silence by cruel 
 responses.  I am far beyond that now, but I remember it well. 
 Furthermore, this list contains quite a few for whom English is not a 
 first language. I am grateful to everyone here for being on the list 
 and helping those who come to it for assistance. We all get frustrated 
 with simplistic or repetitive questions, and people who don't even try 
 should be told to try first, but very little besides a bully's ego is
 helped by mean replies. No?
 
 Thanks again, all of you, really.
 
 On Jan 10, 2013, at 3:36 PM, Lou Pereira louis.pere...@ptalc.com
 wrote:
 
 I beg to differ regarding your comment.  I have been trying to be 
 removed from this list for over a year to no avail.  So, all 
 knowledge one, how do we remove ourselves from this mail list?
 
 
 
 -Original Message-
 From: klamerus [mailto:klame...@earthlink.net]
 Sent: Thursday, January 10, 2013 4:10 PM
 To: 'bhanu chaitanya abbaraju'; beginners@perl.org
 Subject: RE: Hi
 
 Since you clearly don't know how mailing lists work I'm afraid that's 
 not possible.
 
 -Original Message-
 From: bhanu chaitanya abbaraju [mailto:bhanu.cha...@gmail.com]
 Sent: Thursday, January 10, 2013 2:04 PM
 To: beginners@perl.org
 Subject: Hi
 
 Please help me how can I stop perl emails
 
 --
 A.Bhanuchaitanya
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 
 
 
 
 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional 
 commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
 
 
 -- 
 To 

Re: Hi

2013-01-14 Thread Bill Stephenson
Hi Lou,

You might want to make sure you're sending your email in plain text. 

Check your settings, if you're using Rich Text or HTML to format the email 
it might screw the pooch for you. That's a real old problem, but this might be 
real old software running this list.

Also, I found this on the faq page for this list:

Who owns this list? Who do I complain to?
John SJ Anderson owns the beginners list. You can contact him at 
geneh...@genehack.org.

http://learn.perl.org/faq/beginners.html#owner

Hopefully contacting them will help. If not, let us all know and I'll try and 
help you track down a solution to the problem.

Kindest Regards,

Bill Stephenson



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Line-oriented socket I/O using select()

2013-01-14 Thread Vic Sage
On Jan 13, 2013, at 8:35 PM, Charles DeRykus dery...@gmail.com wrote:

 On Sun, Jan 13, 2013 at 3:03 PM, Vic Sage vic.s...@icloud.com wrote:
 
 What I *want* is to block until an entire \n-terminated string [can that 
 be referred to as a line?]  can be retrieved from one of my clients.  I'm 
 sure I could work out the logic to maintain application-level buffers, but I 
 suspect I would merely be reinventing the wheel, one bug at a time :-).   
 What does the experienced Perl programmer - or socket-level programmer in 
 general - do in this situation?
 
 
 I'm not experienced in heavy duty socket-level programming
 but you may want to invest in learning POE:
 
  https://poe.perl.org
 
 It's already refined many of the wheels you'll need and appears well
 documented.

Wow - that is one substantial package!  POE looks like a pretty steep learning 
curve; however, it appears as if POE::Wheel::ReadWrite might be what is needed. 
 I've never tried my hand at working with event loops - and I'd be interested 
to hear if there's a general consensus that this is much preferable to my 
old-school approach of just looping on a select().