Q: I have the following short perl script that access a MySQL database. The problem is that it is very slow. I was wondering if anyone had any idea about how to accelerate. It may simply be a database connection taking a second, but it seems like it should be 5 times faster than is.
Code: 977 503 977 503 #! / Usr/bin/perl
use strict;
use CGI:: Carp qw (fatalsToBrowser)
use DBI;
use CGI qw (: standard); 977 503 977 503 # Connection to the database
my $ dsn1 = “DBI: mysql: database = site management; some. server.com host = “$ database = DBI-
my u003e connect ($ dsn1, username, password, (Raise Error = 1 u003e automatically capture u003e = 1));
my $ id = param (id )
my si = $ param (“si”);
print “Content-Type: image / jpeg nn”;
if ($ si eq f) (977 503 @ my photos = $ database u003e selectrow_array (qq ~ select image from images where id = $ id ~) print $ 977.503 photos [0])
elsif 977 503 ($ si eq m) (977 503 @ my photos = $ database u003e selectrow_array (qq ~ select key images where id = $ id ~) print $ 977.503 photos [0]) 977 503 977 503
else (my @ photos = $ database u003e selectrow_array (qq ~ select inches from the images where id = id “$” ~); print $ 977.503 photos [0] 977 503 977 503 977 503) $ u003e database disconnect;
exit;
Database Normalization EBook(R.
Re:Try telnet and see how fast it goes.
Social Connect Blueprint
Re:try using wget both on the localhost, and on the client where you're experiencing trouble. compare the exact download times and speeds for both
WhereCode – Area Code Exchange City Database
Re:Those are strange results. The script takes 0.3 seconds to run from start to finish, but the page takes 1.5 seconds to display. Am I correct in that your script displays only a single image? What happens if you access the image as a file instead of as data from the database? At best, we should see pictures taking about 1.2 seconds to display instead. If it is faster than that, then we are not seeing a network problem, and instead it is something to do with how the request is being processed.
I gotta say, I'm a bit baffled. Here's another possibility: are you accessing this script within another web page that uses your script as the source of an image tag? If so, is it possible that the web server is throttling the processing to allow only a low number of scripts to run at a time? It's a long shot…
Keep giving us info as you learn more…
Uae Paid Surveys Database
Re:php trick, so it may or may not be of any use, but when doing an operation like this if you have any kind of output buffering to use it seems to help the "feel".
Example:
Without output buffering a project I'm working out was taking ~5 seconds to display a page with a boatload of queries.
With output buffering it was down to ~3 seconds with the same number of queries.
Don't know if you have anything like that at your disposal, but it may be of some use to clean up some of the "feel".
Connecting You with Everything Bass Fishing!
Re:Ok, I added some timing and logging to the script, here's the output of it:
Starting script (61): 1060378627.491280
Connected to DB : 1060378627.707005
selected image 61 in size t : 1060378627.772814
Sent file to web browser : 1060378627.772898
Disconnected (61): 1060378627.773308
Starting script (49): 1060378629.644127
Connected to DB : 1060378629.860508
selected image 49 in size t : 1060378629.926950
Sent file to web browser : 1060378629.927032
Disconnected (49): 1060378629.927448
Starting script (29): 1060378633.394579
Connected to DB : 1060378633.612555
selected image 29 in size t : 1060378633.678709
Sent file to web browser : 1060378633.678793
Disconnected (29): 1060378633.679210
Starting script (46): 1060378635.520949
Connected to DB : 1060378635.738101
selected image 46 in size t : 1060378635.804699
Sent file to web browser : 1060378635.804852
Disconnected (46): 1060378635.805272
There's a bunch more cases, but those give a genreal idea. The times are in seconds. You can see that the most time consuming operation is establising a database connection, taking about 0.2 seconds on average. Selecting the iamge is actually relatively fast. The entire script is executing in roughly 0.3 seconds, but when accessed from the website, it's taking roughly 1.5 seonds to load each image. They're approximately 5kb each, and the line is at least 3megabit up and down… so it should be faster.
Driver Detective – Industry’s Largest Driver Database
Re:Originally posted by: guy
Have you tried doing any timing? I would suggest two things: 1) Figure out how long each part takes — connecting, querying, then printing the results by putting timing code in your script. 2) Test the speed of your query through some external tool (not your page). It's possible that querying images from your image table takes a while because the size of data.
How many rows of data are in the images table, and is there an index on id?
Yeah, I was thinking the same as you for #1 and #2. Is there really a need to store these images in the database? If possible (and I realize it may not be, especially if the db server is a different host), I would store them on the filesystem and just put the filenames into the database.
e-Tattoo – Online Tattoo Gallery Database
Re:Have you tried doing any timing? I would suggest two things: 1) Figure out how long each part takes — connecting, querying, then printing the results by putting timing code in your script. 2) Test the speed of your query through some external tool (not your page). It's possible that querying images from your image table takes a while because the size of data.
How many rows of data are in the images table, and is there an index on id?
Mystic Connections
Re:Why Perl and ! PHP?
(Sorry, I can not offer you any suggestion)
0 Comments.