1

I have created a website in which there is a Checkout button, whenever the Customer Clicks on the Checkout Button I need to create 4 Image Files in jpg Format and Save them on the Server. These Image Files will be later on printed by the Admin of the Site

Now one of the Image Files could be of 3MB to 4MB in size While the rest of the 3 Images Files will be mostly between 250KB to 500KB in size

Now the problem is the First File which could be from 3MB to 4MB takes some time to be created like 5-10 Secs (this is only when one Customer Checkout at a time)

But when I performed simultaneous Checkout with 2 different Devices, the time frame increased to 20 Secs, one of the Checkout was processed First while the other waited or worked a little slowly, so the total time was 20 Secs, otherwise the time for one of the Checkout was 8 Secs while for the other it was 12 Secs

So I fear that if 10 or 20 Customers performed Checkout simultaneously then some of them might have to wait for perhaps 2 OR 3 Mins or perhaps even more

So can anyone please tell me, how I can increase the rate at which PHP writes file OR to increase the PHP Execution Speed OR Will increasing the RAM might help (currently it is 1GB)

Note :-
->I am using IMagick to create Image Files,
->Also cannot reduce the jpg quality as it will be printer later on at 150 dpi,
->The First Image File is a High Definition Photograph, while the rest 3 are only filled with Solid Colors
->Also their resolutions are High like between 2800 to 4400 pixels in both width and height
->Also there is a Serial Number that is to be added to all 4 Image Files so I cannot reduce it's quality otherwise the Serial Number might not be visible while printing all the 4 Image Files

UPDATE : The Customer First Uploads a Photograph, then he can scale the image, crop it or even move it(for cropping purpose)

So in short he is mainly cropping an uploaded image and when he Clicks on the Checkout Button the new image is created and a Serial Number is added to it

I checked the code the Image gets processed OR created in memory(RAM) in about 1 Sec, but when I add the code for writing the image on the Hard Drive in the Server itself it is then that it takes some amount of time 5-8 Secs if no simultaneous request or 10-15 Mins if 20-30 Simultaneous Request

Also I have to show them a Success or a Failure Message, but I can only show the Success Message after all the 4 images files are created, so even if i use ajax even then I cannot show the Success Message not before all the Images are created

Again if I remove the code for writing the Image then the time reduces to 1 Sec if no simultaneous request or 5-10 Secs if 20-30 Simultaneous Request

So I think the problem is with writing the Image File and not processing or generating it

Also I cannot create the Image File while the user is still cropping the image otherwise it will slow down the cropping process. Also the situation will not change but rather get worse, the problem from "What will happen when Simultaneous Checkout" will change to "What will happen when Simultaneous Crop". So this is not an option

Also I don't think it will look professional if I say that an EMail will be sent to you, informing you whether your Checkout was a Success or Not.

7
  • do you have to create the files from scratch runtime, or could you pre-create them on some file share and use from there?
    – eis
    Dec 13, 2012 at 7:26
  • Trigger a background task to create the files, and email them to the customer when they're done.... at the front-end, just inform the customer to that the images are being built and that they'll be emailed later
    – Mark Baker
    Dec 13, 2012 at 7:29
  • You will never understand your bottleneck without profiling the execution. You may also need an experienced system administrator or someone who can help you understand the performance of your server. Certainly a server with 1GB is under resourced for a lamp stack where you believe you'll have a substantial number of simultaneous users in an apache/mod_php setup. Use top to look at the footprint of the apache child processes to get a better idea of how much memory these scripts need to run, and you'll understand how many of those can fit in your available ram.
    – gview
    Dec 13, 2012 at 7:35
  • The Website is for Cropping Images, so the user upload one Photograph, move it,scale it, crop it and then Clicks on the Checkout Button So I need to create the New Image from scratch and can only start this process when he Clicks on the Checkout Button Thanks Mark Baker for the advice I was thinking of using Ajax to make Asynchronous Request. But what if the PHP Script generated an error this will only be displayed after the Script has finished creating all the files Once all the image files are created only then I wish to show a Success or a Failure Message
    – Aditya
    Dec 13, 2012 at 7:56
  • @gview I think even without the profiling information, it is reasonable that creating 5MB of images on the fly, runtime, will take some time. I would claim that if the files can be pre-created or done as a background process (which makes sense anyway), it will ease the things out, irrelevant of profiling.
    – eis
    Dec 13, 2012 at 7:56

1 Answer 1

0

Just a few thoughts, maybe one of them help you with your task at hand:

  • Try to find out which of the steps you are performing on those images is the one eating away your performance. Maybe show some code, so people can help.
  • Some image operations might take longer because of older hardware (CPU, RAM, HD). Is your hardware good enough?
  • Are you using the latest version of IMagick?
  • Try separating the image processing from the checkout process. Maybe write the raw data into a database, file or whatever first and create a cron (or trigger it) which does the processing, so your users don't have to wait for this.
  • You might have to delve into your php and apache configuration, too. Unoptimized setups might result into performance issues, too.
4
  • The Image files are generated in 1 Sec, but it is the writing process that is taking all the time, if I'll run a loop an Submit 10 Checkout this means I am writing a total of 20-30MB of data, this is bound to take me about 40-50 Secs and yes I am using the Latest IMagick, again there is nothing wrong with IMagick as it create the file in memory in about 1 Sec but it is the writing process that is time consuming
    – Aditya
    Dec 13, 2012 at 8:06
  • 10secs for writing 20-30MB? Why is that? Slow harddiscs, remote fileserver or something else? Anyway, try to separate the processing from the checkout process, this will ease the pain for your users.
    – Bjoern
    Dec 13, 2012 at 9:03
  • Like I said in my Updated question I cannot separate Processing and Checkout because I need to display a Success Or a Failure message depending on the Outcome of the Processing, also it is not the processing that is time consuming but the writing of the files
    – Aditya
    Dec 13, 2012 at 9:33
  • Well, without some code and some insight into your hardware components, setup etc, its hard to give advice. If it really is the writing, there must be some limiting factor in your general setup.
    – Bjoern
    Dec 13, 2012 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.