Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
08-17-2012, 10:19 AM
|
#1
|
LQ Newbie
Registered: Nov 2010
Posts: 13
Rep:
|
Cat command I/O intensive question.
Hello all,
I'm still pretty new to Linux servers. I'm working on a project for a web server, and one of my team members said that we need to cut back on I/O intensive commands. He told me to start at looking at all the scripts that use the cat command because they are I/O intensive.
I wasn't aware of till he mentioned it that the cat command was I/O intensive. What could I do that's more efficient. Should I write something in perl, awk, c++? Or is the cat command more efficient?
Why is the cat command so I/O intensive? ( so that I have a better understanding)
Thank you!
|
|
|
08-17-2012, 11:07 AM
|
#2
|
Member
Registered: Jul 2010
Posts: 231
Rep:
|
I think its the file size what matter.
We had a guy who would less/vi on multi-GB files almost crashed machines every time.
Play with iostat/vmstat while you are opening file or doing other task, that will give you idea according to your
environment.
you can do
Quote:
>watch iostat
> watch vmstat
|
Last edited by PoleStar; 08-17-2012 at 11:09 AM.
|
|
|
08-17-2012, 11:30 AM
|
#3
|
LQ Newbie
Registered: Nov 2010
Posts: 13
Original Poster
Rep:
|
Thanks for the watch iostat command. I'll see what I can do...
The problem is the person who designed the program on the web server used the cat command for a lot of the scripts. it frequently uses the cat command to parse through a file. I haven't looked through all the perl scripts yet, but the developer used the cat command a lot to read files in. I don't know how inefficient that can be.. Like I said I'm still new. So I'm trying to figure out how to make things more efficient
|
|
|
08-17-2012, 11:50 AM
|
#4
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,797
|
Quote:
Originally Posted by neoanomally
The problem is the person who designed the program on the web server used the cat command for a lot of the scripts. it frequently uses the cat command to parse through a file.
|
Useless use of cat is inefficient, but I don't think it would increase disk IO: it just means that the file gets copied into cat's memory and then copied to the invoking program's memory. So extra memory copying, not extra disk reading.
|
|
|
08-17-2012, 12:37 PM
|
#5
|
LQ Newbie
Registered: Jan 2012
Posts: 24
Rep:
|
neoanomally, use command like sed or awk for file manipulation. They are more effient with files. Perl also does a good job if the job is too complicated. Regarding io r/w iotop gives a good information
|
|
|
08-19-2012, 07:40 PM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,398
|
It sounds like its more a case of just using too much bash scripting in general, which tends to invoke a lot of external cmds/utils like cat.
You should be able to re-write them all in eg native Perl.
Just make sure you use the internal Perl cmds; don't start making lots of external calls like some people do
Useful links
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials
http://www.tizag.com/perlT/index.php
|
|
|
08-20-2012, 08:16 AM
|
#7
|
LQ Newbie
Registered: Nov 2010
Posts: 13
Original Poster
Rep:
|
That's what I figured I would do. I just wasn't sure how much the external calls were going to affect the processes. After looking at many of the processes that are currently written, it looks like the previous programmer used external script calls whenever possible. So it looks like I have my work cut out for me.
Also, thanks for the links!!! tizag, has been the most helpful perl information online I've seen so far!
|
|
|
08-20-2012, 09:00 PM
|
#8
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,398
|
Been There, Done That
Worked at a place that had an old bash/sed/awk etc script that took ~2 days to run on a small amt of data, in fact they stopped running it.
I re-wrote in Perl and used a lot(!) more data and got it down to ~1.5 hrs
That's also why you should not keep firing off the same cronjob every minute... My rule of thumb is that if you want that every 5 mins or more frequently, just write a daemon and wait at the bottom of the loop as reqd.
Also stops it tripping over other copies of itself.
|
|
|
All times are GMT -5. The time now is 11:57 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|