Home > Archive > PERL CGI Beginners > September 2004 > Several images from same cgi script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Several images from same cgi script
|
|
| Sean Davis 2004-09-14, 3:55 am |
| I have a cgi-script that needs to generate a batch of images and insert them into the HTML. I am currently doing this using a "helper" script that does the generation for each image and the call to this script and parameters are in an img tag. However, if I submit this page to the server, several of the images are not created and show up as missing images, but some do show up (different each submission). What I would really like to do is to generate all of the images with one run of a script and insert them that way. I could do this with temporary files, but each call has the potential to make several tens of files, with multiple calls in a row (depending on user direction). Is there a way that I can do this, either without temporary files or, if with temp files, some direction about how to keep the files manageable?
Thanks,
Sean
| |
| Chris Devers 2004-09-14, 3:55 am |
| On Mon, 13 Sep 2004, Sean Davis wrote:
> I have a cgi-script that needs to generate a batch of images and
> insert them into the HTML.
Do the images tend to be unique for each user, or will the script end up
generating the same image for multiple visitors?
If everyone is getting unique images, then your best bet may be some
kind of caching mechanism.
If the same image tends to go out to multiple users, then there can
probably be a lot to be gained by stashing those images (as long as the
storage doesn't get unweildy) and then having the script attempt to
serve a pre-prepared image before reverting to making a new one. (This
amounts to caching again, but in a smarter way than the other case,
where it may be easier to just put Squid in front of your server...)
Make sense?
--
Chris Devers
| |
| Sean Davis 2004-09-14, 3:55 am |
| Chris,
Thanks for the reply. To answer your questions, they will be presenting the
same information to all users, but to pre-build will result in about 200,000
files (all on the order of 10-20KB, png [they include text]). Storage isn't
really an issue, I don't think, but just felt more elegant to compute on the
fly.
Sean
-----Original Message-----
From: Chris Devers
To: Davis, Sean (NIH/NHGRI)
Cc: beginners-cgi@perl.org
Sent: 9/13/2004 1:01 PM
Subject: Re: Several images from same cgi script
On Mon, 13 Sep 2004, Sean Davis wrote:
> I have a cgi-script that needs to generate a batch of images and
> insert them into the HTML.
Do the images tend to be unique for each user, or will the script end up
generating the same image for multiple visitors?
If everyone is getting unique images, then your best bet may be some
kind of caching mechanism.
If the same image tends to go out to multiple users, then there can
probably be a lot to be gained by stashing those images (as long as the
storage doesn't get unweildy) and then having the script attempt to
serve a pre-prepared image before reverting to making a new one. (This
amounts to caching again, but in a smarter way than the other case,
where it may be easier to just put Squid in front of your server...)
Make sense?
--
Chris Devers
| |
| Chris Devers 2004-09-14, 3:55 am |
| On Mon, 13 Sep 2004, Davis, Sean (NIH/NHGRI) wrote:
> Thanks for the reply. To answer your questions, they will be
> presenting the same information to all users, but to pre-build will
> result in about 200,000 files (all on the order of 10-20KB, png [they
> include text]). Storage isn't really an issue, I don't think, but
> just felt more elegant to compute on the fly.
It depends what you want to optimize for.
What is the overhead for generating 200k images on the fly?
How much disc space will it take to generate them all -- perhaps as an
offline batch routine -- and serve up the pre-generated file on demand?
If your server is already busy, generating everything on the fly might
be a lot of overhead; if you have the disc space for it, generating and
storing all these files might not be such a bad idea.
Certainly, making them in advance should get you around the problem of
the images sometimes not showing up -- or so I would hope...
--
Chris Devers
| |
| Sean Davis 2004-09-14, 3:55 am |
| I only need a subset (on the order of 10's or 100's of images) for each
script invocation, but what I have doesn't work, so I will probably just
precompute and pull them up as needed.
Sean
-----Original Message-----
From: Chris Devers
To: Davis, Sean (NIH/NHGRI)
Cc: 'beginners-cgi@perl.org '
Sent: 9/13/2004 1:31 PM
Subject: RE: Several images from same cgi script
On Mon, 13 Sep 2004, Davis, Sean (NIH/NHGRI) wrote:
> Thanks for the reply. To answer your questions, they will be
> presenting the same information to all users, but to pre-build will
> result in about 200,000 files (all on the order of 10-20KB, png [they
> include text]). Storage isn't really an issue, I don't think, but
> just felt more elegant to compute on the fly.
It depends what you want to optimize for.
What is the overhead for generating 200k images on the fly?
How much disc space will it take to generate them all -- perhaps as an
offline batch routine -- and serve up the pre-generated file on demand?
If your server is already busy, generating everything on the fly might
be a lot of overhead; if you have the disc space for it, generating and
storing all these files might not be such a bad idea.
Certainly, making them in advance should get you around the problem of
the images sometimes not showing up -- or so I would hope...
--
Chris Devers
| |
| Chris Devers 2004-09-14, 3:55 am |
| On Mon, 13 Sep 2004, Davis, Sean (NIH/NHGRI) wrote:
> I only need a subset (on the order of 10's or 100's of images) for each
> script invocation, but what I have doesn't work, so I will probably just
> precompute and pull them up as needed.
I realize that this is awfully hand-wavey, but I've seen systems that
handle situations like this by first attempting to use a pre-computed
image (or whatever storable expensive-to-compute-thing is relevant)
and if one isn't available, then making one, saving it, then serving
both now and in the future. This makes the first hit slow, but future
ones fast, which is often reasonable.
As rough pseudocode, this would be something like the below:
my $CGI = new CGI;
my $stash_img = munge_params_into_filename( $CGI );
my $image = check_for_existance( $stash_img ) or
generate_and_stash( $stash_img, $CGI );
serve_image( $image );
exit 0;
Fleshing out these subroutines is an exercise for the reader :-)
--
Chris Devers
|
|
|
|
|