1

I have 500k unique images in my folder/directory. I want call it by name and all names are stored in Mysql database. but I heard that images can be stored in a database. So my question is which is more fastest option to display image faster. do I need to store in mySQl or can I keep same method which I am following?

If I need to store in mySQL then how do I create a table for it, and how do I store all these images?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
leon
  • 151
  • 1
  • 7
  • 1
    how do you think yourself which is faster? Just by comparing operations, required to display an image – Your Common Sense Jan 26 '11 at 09:20
  • 2
    Don't store all 500k images in a single directory... have 100 subdirectories holding 5k images each. – Mark Baker Jan 26 '11 at 09:34
  • @Mark Baker I am interested if you got benchmarks to proof your statement? – Alfred Jan 26 '11 at 12:05
  • 1
    @Alfred - I've never benchmarked, and plucked the figures 100 and 5k out of the top of my head. However, the principles behind reduced performance of very large directories are well known, as is the solution. sarnold has given a better explanation in his answer. – Mark Baker Jan 26 '11 at 12:07

6 Answers6

6

This has been answered quite a few times. But you haven't talked about what type of application that you are building, if you are building a web application then storing the images on the file system has advantages re: caching.

Storing Images In Filesystem As Files Or In BLOB Database Field As Binaries

Storing Images in DB - Yea or Nay?

It's easy enough to store the images in a table, I would definitely avoid it though if your images are quite large.

Community
  • 1
  • 1
nixon
  • 1,952
  • 5
  • 21
  • 41
4

I do not think 500k entries in a single directory will go over very well: How many files can I put in a directory?

Once upon a time, Linux ext3 started running slowly for very simple operations once a directory accumulated around 2000 files. (O(N) sorts of slowly!) After the htree patches were merged, large directory performance improved drastically, but I'd still recommend partitioning your image store based on some very easy criteria. (Squid web cache, for example, creates directory trees like 01/, 02/, and places files based on the first two characters in the filename.)

Community
  • 1
  • 1
sarnold
  • 102,305
  • 22
  • 181
  • 238
3

Do not store so many data in a db like mysql especially if you are not so familiar like you sound. Keep the images on the fs

dynamic
  • 46,985
  • 55
  • 154
  • 231
2

I have 500k unique images in my folder/directory. I want call it by name and all names are stored in Mysql database. but I heard that images can be store in database. so my question is which is more fastest option to display image faster.

You should use the file system. Storing in database is not going to work very well. You should read Facebook Photo Storage Architecture to learn how facebook does it. They have the most photos in the world.

Haystack file storage:

enter image description here

Also interesting: http://www.fredberinger.com/high-performance-at-massive-scale-lessons-learned-at-facebook/

Alfred
  • 60,935
  • 33
  • 147
  • 186
1

Storing images into the database (in a blob datatype) in much more inefficient than keep those images stored on the file system.

BTW here is explained how to insert binary data into a mysql table

Francesco Laurita
  • 23,434
  • 8
  • 55
  • 63
0

If you have Redis, you could put all the images in memory, that would be the quickest way

Tyler Gillies
  • 1,857
  • 4
  • 22
  • 31