Last modified by Pascal Robert on 2011/02/22 10:35

From version 7.1
edited by Pascal Robert
on 2011/02/22 10:35
Change comment: There is no comment for this version
To version 8.1
edited by Pascal Robert
on 2011/02/22 10:35
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -8,7 +8,7 @@
8 8  
9 9  Keep in mind that the purpose of a database is to store data to be search and retrieved.
10 10  
11 -It would be a rare case when you'd actually send a query to a database that consisted of an image blob (i.e. search for an image that matches certain binary data). More than likely, you'd perform a search for an image based on its meta-data like date, time, image name, or file system path. A good solution is to store the path to the medium and then simply build the reference URL for the client's browser to reference or have the application retrieve the medium from the file system and serve it up through the WebObjects adaptor. In the former case you can keep the media under the Web server (say image thumbnails) and, in the latter case, you can keep full size images anywhere else on the server's file system and server them up based on a user's profile (i.e. did they successfully check out?, etc).
11 +It would be a rare case when you'd actually send a query to a database that consisted of an image blob (i.e. search for an image that matches certain binary data). More than likely, you'd perform a search for an image based on its meta-data like date, time, image name, or file system path. A good solution is to store the path to the medium and then simply build the reference URL for the client's browser to reference or have the application retrieve the medium from the file system and serve it up through the WebObjects adaptor. In the former case you can keep the media under the Web server (say image thumbnails) and, in the latter case, you can keep full size images anywhere else on the server's file system and server them up based on a user's profile (i.e. did they successfully check out?, etc).
12 12  
13 13  == Michael Engelhart ==
14 14  
... ... @@ -25,10 +25,10 @@
25 25  In either case you will be transporting the binary data for the images across the network either directly via a share, or through the database connection. I personally take the easy way out and store the images in the database.
26 26  
27 27  An Example:
28 -Say I have a Product entity and want to upload and store product photos: I would create two entities Product and ProductPhoto. I would then relate them with either a toOne or toMany relationship depending on whether I need one or many ProductPhoto objects for each Product object.
28 + Say I have a Product entity and want to upload and store product photos: I would create two entities Product and ProductPhoto. I would then relate them with either a toOne or toMany relationship depending on whether I need one or many ProductPhoto objects for each Product object.
29 29  
30 30  With this design pattern fetching Product data doesn't directly load the images. Instead EOF will create faults representing the images.
31 -The image data isn't fetched until the fault is fired by accessing the ProductPhoto fault object. So If you fetch 500 Products and batch them into groups of 10 with the WODisplayGroupWO:Programming~_~_WebObjects-Web Applications-Development-WODisplayGroup then your first page would fetch only the first 10 images not the 500 (and only if there is a WOElement? or method that accesses the image data).
31 + The image data isn't fetched until the fault is fired by accessing the ProductPhoto fault object. So If you fetch 500 Products and batch them into groups of 10 with the [ WODisplayGroup|WO:Programming~_~_WebObjects-Web Applications-Development-WODisplayGroup] then your first page would fetch only the first 10 images not the 500 (and only if there is a WOElement? or method that accesses the image data).
32 32  
33 33  This pattern also greatly simplify uploading and storing the images because you can bind the NSData used to upload the image to your ProductPhoto's imageData BLOB.
34 34  
... ... @@ -35,7 +35,7 @@
35 35  It's probable that many will disagree with me on this issue, but I have had good success, for my purposes, with this design pattern.
36 36  
37 37  You can find an implementation of this design pattern for both toOne and toMany photos in the JavaRealEstate framework example in
38 -/Developer/Examples/JavaWebObjects/Frameworks.
38 + /Developer/Examples/JavaWebObjects/Frameworks.
39 39  
40 40  == Michael Halliday ==
41 41  
... ... @@ -51,18 +51,18 @@
51 51  Again, I know many people will probably disagree with this approach. But, it is working perfectly for us and for dynamic images (or images that the user can change/upload) I think it's the most effective approach. That being said, we do use apache to serve up our static images.
52 52  
53 53  I'd be interested to hear from others and there experiences with storing images in databases. You hear a lot of people saying "Don't do it, it won't perform well."...but have these people actually tried it? Or have they just been told not to do it. I have been very interested in this topic for a while now and I have done extensive searching but
54 -never come up with any "correct" answer. I think it also depends on which database you use and how exactly the database itself stores images. I know that some are much better than others and personally this is where you'd most likely run into the performance hit (if any).
54 + never come up with any "correct" answer. I think it also depends on which database you use and how exactly the database itself stores images. I know that some are much better than others and personally this is where you'd most likely run into the performance hit (if any).
55 55  
56 56  == Geoff Hopson ==
57 57  
58 -On the Fortnum & Mason online store [[http://www.fortnumandmason.com]], the product catalog is pretty image-heavy. Also, they (F&M) change the catalog and the associated images at least twice a year. So I wrote a tool that allows their product images to be uploaded into the database, simply for the purpose of having everything in a single place for
59 -backup reasons. When a new catalog is ready to be deployed, the images are extracted from the database and placed under the webserver (since, as everyone notes, webservers are particularly good at vending images). The main F&M web application then gets all it's images from the webserver, as opposed to cached in the webobjects application after a fetch from the database.
58 +On the Fortnum & Mason online store [[http:~~/~~/www.fortnumandmason.com>>url:http://www.fortnumandmason.com||shape="rect"]], the product catalog is pretty image-heavy. Also, they (F&M) change the catalog and the associated images at least twice a year. So I wrote a tool that allows their product images to be uploaded into the database, simply for the purpose of having everything in a single place for
59 + backup reasons. When a new catalog is ready to be deployed, the images are extracted from the database and placed under the webserver (since, as everyone notes, webservers are particularly good at vending images). The main F&M web application then gets all it's images from the webserver, as opposed to cached in the webobjects application after a fetch from the database.
60 60  
61 61  However, in development, we used the images from the database directly. Command line switch toggles whether the images are read from the webserver or the database.
62 62  
63 63  Doing all this means that the memory footprint is lower, since the application is not caching images, and it also means that we can do clever things with the webserver to spread the load a little.
64 64  
65 -Chuck Hill wrote something on the pros and cons of using the webserver yesterday - [[http://lists.apple.com/mhonarc/webobjects-dev/msg05564.html]] (use 'archives', 'archives' as the username/password).
65 +Chuck Hill wrote something on the pros and cons of using the webserver yesterday - [[http:~~/~~/lists.apple.com/mhonarc/webobjects-dev/msg05564.html>>url:http://lists.apple.com/mhonarc/webobjects-dev/msg05564.html||shape="rect"]] (use 'archives', 'archives' as the username/password).
66 66  
67 67  == Arturo PĂ©rez ==
68 68  
... ... @@ -78,7 +78,7 @@
78 78  
79 79  * There are some tuning issues around BLOBs if you're using those (or equivalent).
80 80  * I don't understand people saying "It solves single point of failure." Didn't you just move the single point of failure from a file system to the database? Sure, databases offer replication but you can achieve the same with a clusterable file system like Transarc or the Andrew File System (AFS).
81 -* It "makes no sense." It's just storing a bunch of non-relational data in a relational database. It feels unclean :-)
81 +* It "makes no sense." It's just storing a bunch of non-relational data in a relational database. It feels unclean
82 82  * If you need to manipulate the data it's much much harder. For example, if it's text and you want to fix a typo it's problematic. If it's an image updating EXIF headers would be a chore. It's much easier to run a perl script over a directory of files.
83 83  
84 84  Filesystem pros:
... ... @@ -101,7 +101,7 @@
101 101  Another alternative is to store them on the file system but not directly available to the web server. Keep an object in the database that references the data on the file system. Use Java streams to move the data from the request to the file system and from the file system into the response. This avoids the EOF overhead but allows your application to control access. It is much more efficient to have the web server directly access and vend the images etc. but if you have access restrictions this is not an option. This hybrid database / file system approach can be useful in that situation.
102 102  
103 103  PetiteAbeille wrote about an EOF file system adaptor that may be of interest in relation to this question:
104 -[[http://www.wodeveloper.com/omniLists/eof/2002/June/msg00053.html]]
104 + [[http:~~/~~/www.wodeveloper.com/omniLists/eof/2002/June/msg00053.html>>url:http://www.wodeveloper.com/omniLists/eof/2002/June/msg00053.html||shape="rect"]]
105 105  
106 106  == Tom Pelaia ==
107 107  
... ... @@ -123,11 +123,11 @@
123 123  
124 124  I happily store images in the database, but... my clients use Oracle or FrontBase. The very now though I have the misfortune to work on an application which has to use the MS-SQL thing: seems it really does not support BLOBs well (actually, the database admin just plain told me "do not use a BLOB in your tables, ever~-~-we have the worst experience with them").
125 125  
126 -Myself, I've tried of course :-) (with a test database) and found that indeed there seem to be issues, like that a BLOB is never found by a WHERE clause (even if a proper value is provably given). I haven't tested for long :-)
126 +Myself, I've tried of course (with a test database) and found that indeed there seem to be issues, like that a BLOB is never found by a WHERE clause (even if a proper value is provably given). I haven't tested for long
127 127  
128 -Thus, although I am a strong believer in storing images in the database, I can understand others who are unlucky enough not to be FrontBase users might have different opinions :-)
128 +Thus, although I am a strong believer in storing images in the database, I can understand others who are unlucky enough not to be FrontBase users might have different opinions
129 129  
130 -The reason I am writing: before deciding where to store your images, do check the concrete database to be used. If FrontBase or Oracle, you probably would want to store them in the database, if MS-SQL, you probably would want to store them in the filesystem :-)
130 +The reason I am writing: before deciding where to store your images, do check the concrete database to be used. If FrontBase or Oracle, you probably would want to store them in the database, if MS-SQL, you probably would want to store them in the filesystem
131 131  
132 132  == Jeff ==
133 133  
... ... @@ -189,15 +189,15 @@
189 189  
190 190  == Bill Bumgarner ==
191 191  
192 -Storing images in the database is generally a bad idea for a whole slew of reasons. First and foremost, it is loads slower than serving images directly from the web server and it completely bypasses numerous automatic "optmiziations" that are present when serving from a filesystem. If it can't be avoided, it can't be avoided.... however, if you have any hopes of scaling your solution to a large community of users or a heavy hit rate, expect to expend a lot of engineering and hardware dollars making images-in-the-database go fast.
192 +Storing images in the database is generally a bad idea for a whole slew of reasons. First and foremost, it is loads slower than serving images directly from the web server and it completely bypasses numerous automatic "optmiziations" that are present when serving from a filesystem. If it can't be avoided, it can't be avoided.... however, if you have any hopes of scaling your solution to a large community of users or a heavy hit rate, expect to expend a lot of engineering and hardware dollars making images-in-the-database go fast.
193 193  
194 194  In particular:
195 195  
196 -Images are normally served statically from the filesystem... because you are now serving them as dynamic content, the following performance hits occur:
196 +Images are normally served statically from the filesystem... because you are now serving them as dynamic content, the following performance hits occur:
197 197  
198 -* no client side caching [[WO:ouch]] five copies of a single image on a page yields five seperate hits on WO.
199 -* image requests must be serialized- not only do IMAGE hits have to be serialized, but all other hits on the WOF app will have to wait for any pending image hits to be handled. In terms of Netscape's REALLY SLOW table layout algorithm that requires the size of all images to be known, this means that the user WON'T see the contents of the table until ALL image hits have returned at least the size of the image.... since hits are serialized, that means that all but the last image must be entirely handled.
200 -* performance difference between a static hit vs. a fully dynamic hit is tremendous [[WO:in favor of static]]. Think about it... a static hit basically means the web server opens a file, reads/writes the contents to a socket, closes... dynamic hits require IPC, a database round trip [[WO:maybe]], a bunch of memory munging, a pass through request/response, etc.etc.etc...
198 +* no client side caching [[doc:WO.ouch]] five copies of a single image on a page yields five seperate hits on WO.
199 +* image requests must be serialized~-~- not only do IMAGE hits have to be serialized, but all other hits on the WOF app will have to wait for any pending image hits to be handled. In terms of Netscape's REALLY SLOW table layout algorithm that requires the size of all images to be known, this means that the user WON'T see the contents of the table until ALL image hits have returned at least the size of the image.... since hits are serialized, that means that all but the last image must be entirely handled.
200 +* performance difference between a static hit vs. a fully dynamic hit is tremendous [[doc:WO.in favor of static]]. Think about it... a static hit basically means the web server opens a file, reads/writes the contents to a socket, closes... dynamic hits require IPC, a database round trip [[doc:WO.maybe]], a bunch of memory munging, a pass through request/response, etc.etc.etc...
201 201  * no server side caching; every instance of your app will end up with a copy of every image served in its memory. As well, the IPC between database and WO app server will have to pass all that data back and forth, as well.
202 202  * most databases are not designed to handle BLOBs well.... regardless
203 203  
... ... @@ -204,6 +204,6 @@
204 204  Alternatives?
205 205  
206 206  Stick a path in the filesystem in your database instead of a blob; abstract arbitrarily to facilitate administration, etc...
207 -If you REALLY need the images to come from the database, build an image manager that maintains a hierarchy of the images in the filesystem and arbitrates the updates between the database and the images.
207 + If you REALLY need the images to come from the database, build an image manager that maintains a hierarchy of the images in the filesystem and arbitrates the updates between the database and the images.
208 208  
209 -One thought; if an image needs to be refreshed and you are worried about client-side or proxying-firewall caching, rename the image in the filesystem (or move it) and generate a new URL- this should be the image managers responsibility.
209 +One thought; if an image needs to be refreshed and you are worried about client-side or proxying-firewall caching, rename the image in the filesystem (or move it) and generate a new URL~-~- this should be the image managers responsibility.