views:

268

answers:

2

Just wondering what the common solution is for this. We have two web servers that are load balanced and a separate server that holds our images. Our current process is that a user uploads an image directly to the web server (which ever they are connected to) and we enter a job into our DB. Another process checks for image jobs every few mins and copies the image from the web server up to the image server.

The delay from when a user uploads to when its visible is not ideal. We could tighten the loop on how often we check for image jobs but ideally I would like to have user uploaded images to go directly to the image server rather than copying twice. How should this be done? Is there anything in spring to deal with this ? Seems like how most would deal with a CDN i would think?

I want to limit the time it takes for an image that a user uploads is available on our site...

A: 

You could insert the image on upload into your db. When the image is requested and it is not in the filesystem, you then can deliver it from db and at the same time sync it to the filesystem. If you don't want to hold all images in the db, you then could also delete it from there in the same step.

Dominik
hmm, seems like that would be a little less performent for all image requests. It would have to check if the file is on disk every time ( or check the DB ) and then decide what to do. Syncing it at request time for a 3 MB file wouldnt scale well either right?
Prem
@Prem: We have a solution like this running with Apache. Apache offers a possibility to specify an alternate url when the original file is not there. The transfer from the database hits you only once and the time it needs to copy in the local network is probably not noticable compared to the time to deliver it over the internet.
Dominik
Hmm, our machines are hosted so the transfer still has some delay..
Prem
Maybe you could provide a description of you setup, which seems a little unusual, where the production db and the production servers are not on the same lan?
Dominik
A: 

Just give the webapp direct access to the imageserver so that it can instantly save the image on the image server. I don't see how that forms a problem.

BalusC
"direct access to the image server" What do you mean? How would you literally do this with apache/tomcat/java ?
Prem
Either by network disk mapping so that you can just access it as if it's on local disk file system, or by FTP by installing a FTP Server on imageserver machine (FileZilla?) and using a FTP client to send the image (Apache Commons Net FTPClient?).
BalusC