Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > Linux Operating System

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-18-2008, 06:57 PM
Doesn't Work At McDonalds
 
Posts: n/a
Default Most Efficient Directory Structure?

So, my new web server will be set-up soon and I'm going to be running a
suite of applications that will let people upload files. The files
will be have a description stored in a database and be given a random
filename equal to their unique ID in the database before they're
stored.

With the filename being a random sequence of letters and numbers, the
maximum number of files I can store is limited to 36 ^ filename length.
At just 8 chars, it's over 2 trillion. I'm not worried there.

So I'm trying to figure out how I set up the directory structure for
maximum expandability and maximum efficiency. If my new site is
unsuccessful, it won't matter. But if it is... I could eventually have
millions of files and I'd hate to be recoding everything to use a new
directory structure, then trying to shift all those files around when I
already had tens or hundreds of thousands of files stored.

What I'm trying to figure out is:

A: How to design so it can easily be spread over multiple disks. Seems
subdirectories based on the initial letters of the filenames would
work. For example, /home/myusername/stuff/A, /home/myusername/stuff/B,
and /home/myusername/stuff/1, could each be mounted to a different
physical drive in an external array, giving me 36 * average drive size
expandability. And because the filenames are randomly generated, the
distribution should be fairly even.

B: How to design for fastest reads and writes. What I'm wondering is
where the tipping point is in terms of number of files or subdirs
degrading write/read/seek speed? Am I better off putting 360,000 files
in one directory, or subdividing that into 36 subdirectories of 10,000
files each, or perhaps subdividing further into 1296 subdirectories (36
subdirectories with 36 subdirectories within them) of 278 files each?

Technically, with an 8-character filename, I have over two trillion
filenames available and could have over two trillion subdirectories,
each 11 levels deep (for example...
/home/myusername/stuff/1/T/6/Y/B/0/P/R/1T6YB0PR.file). But since I'd
have to do a series of mkdir commands each time I stored a file, that
could slow performance. Plus deep in my long-term-storage there's a
memory of a server jockey telling me that each subdirectory requires a
separate disk read which slows performance and wears the drive out
faster.

So where's the sweet spot in keeping the directory structure as simple
as possible while keeping the best speed on writes, reads, and seeks?

Thanks for any input.

- Greg

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-18-2008, 06:57 PM
H.Xu
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

Why not store files themselves in a database? Then you do not need to
worry about too many files. You may worry about backup though.

On Nov 7, 12:03 pm, "Doesn't Work At McDonalds" <burger...@gmail.com>
wrote:
> So, my new web server will be set-up soon and I'm going to be running a
> suite of applications that will let people upload files. The files
> will be have a description stored in a database and be given a random
> filename equal to their unique ID in the database before they're
> stored.
>

[snip]

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-18-2008, 06:58 PM
Hactar
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

In article <1162901006.244376.74130@h54g2000cwb.googlegroups. com>,
Doesn't Work At McDonalds <burgerguy@gmail.com> wrote:
>
> So I'm trying to figure out how I set up the directory structure for
> maximum expandability and maximum efficiency.


What was that line about "a man cannot serve two masters"...

> B: How to design for fastest reads and writes. What I'm wondering is
> where the tipping point is in terms of number of files or subdirs
> degrading write/read/seek speed? Am I better off putting 360,000 files
> in one directory, or subdividing that into 36 subdirectories of 10,000
> files each, or perhaps subdividing further into 1296 subdirectories (36
> subdirectories with 36 subdirectories within them) of 278 files each?


You may have to change filesystems as time goes on. What's the expected
size on a file? Does the access date matter?

> Technically, with an 8-character filename, I have over two trillion
> filenames available and could have over two trillion subdirectories,
> each 11 levels deep (for example...
> /home/myusername/stuff/1/T/6/Y/B/0/P/R/1T6YB0PR.file). But since I'd
> have to do a series of mkdir commands each time I stored a file, that
> could slow performance.


Might a "if not successful (readdir) then mkdir" be faster?

> Plus deep in my long-term-storage there's a
> memory of a server jockey telling me that each subdirectory requires a
> separate disk read which slows performance and wears the drive out
> faster.


The directory will most likely be cached, so it may slow performance
(not much, as it's in RAM), but won't hit the disk.

> So where's the sweet spot in keeping the directory structure as simple
> as possible while keeping the best speed on writes, reads, and seeks?


You need to say what the expected mix of those are, before any decent
recommendations can be offered.

--
-eben QebWenE01R@vTerYizUonI.nOetP royalty.no-ip.org:81

And we never failed to fail / It was the easiest thing to do -- CSN

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-18-2008, 06:58 PM
Doesn't Work At McDonalds
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

H.Xu wrote:
> Why not store files themselves in a database? Then you do not need to
> worry about too many files. You may worry about backup though.


First, it's an automatic performance hit. Retrieving the file from the
database and serving it programatically requires more CPU and disk
activity than directly linking to the file. That means slower serving
and more wear and tear on the server.

Second, I've had a very large database and the larger it got, the more
maintenance had to be done on it to keep things flowing smoothly.

Third, IIRC, most filesystems have a maximum size for a single file and
the database "data" is kept in one file per table. So, if that limit
is 4 gigs, then I'd have to create a new table each time I started
approaching the 4 gig limit. On a 500gb drive with 400 gigs allocated
to files, that would require distributing the files across 100 tables.
The mechanisms needed to manage that would create additional overhead
to slow things down.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-18-2008, 06:58 PM
Doesn't Work At McDonalds
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

Hactar wrote:
> > So I'm trying to figure out how I set up the directory structure for
> > maximum expandability and maximum efficiency.

>
> What was that line about "a man cannot serve two masters"...


Heh. :-)

> You may have to change filesystems as time goes on. What's the expected
> size on a file? Does the access date matter?


Ranges from about 8k to 800k. Access date is unimportant.

> Might a "if not successful (readdir) then mkdir" be faster?


Definite possibility.

> > So where's the sweet spot in keeping the directory structure as simple
> > as possible while keeping the best speed on writes, reads, and seeks?

>
> You need to say what the expected mix of those are, before any decent
> recommendations can be offered.


Write-occasionally, read and seek often.

- Greg

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-18-2008, 06:58 PM
Hactar
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

In article <1162913330.391245.306810@h48g2000cwc.googlegroups .com>,
Doesn't Work At McDonalds <burgerguy@gmail.com> wrote:
> Hactar wrote:
>
> > You may have to change filesystems as time goes on. What's the expected
> > size on a file? Does the access date matter?

>
> Ranges from about 8k to 800k. Access date is unimportant.


OK, not sure of the layout or filesystem, but an easy gain is to mount
it "-o noatime". If the files were generally small, I'd say to follow
the recommendations for a news spool.

> > > So where's the sweet spot in keeping the directory structure as simple
> > > as possible while keeping the best speed on writes, reads, and seeks?

> >
> > You need to say what the expected mix of those are, before any decent
> > recommendations can be offered.

>
> Write-occasionally, read and seek often.


Then you'll see bigger gains by improving read/seek performance at the
expense of write performance (to an extent).

--
"The Web brings people together because no matter what kind of a
twisted sexual mutant you happen to be, you've got millions of pals
out there. Type in 'Find people that have sex with goats that are on
fire' and the computer will say, 'Specify type of goat.'" -- Rich Jeni
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-18-2008, 06:58 PM
Moe Trin
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

On 7 Nov 2006, in the Usenet newsgroup comp.os.linux.setup, in article
<1162901006.244376.74130@h54g2000cwb.googlegroups. com>,
Doesn't Work At McDonalds wrote:

>So, my new web server will be set-up soon and I'm going to be running a
>suite of applications that will let people upload files.


Hope you are filtering lest you become a WareZ server

>With the filename being a random sequence of letters and numbers, the
>maximum number of files I can store is limited to 36 ^ filename length.
>At just 8 chars, it's over 2 trillion. I'm not worried there.


Yeah, in theory your file system would run out of space long before that.

>So I'm trying to figure out how I set up the directory structure for
>maximum expandability and maximum efficiency. If my new site is
>unsuccessful, it won't matter. But if it is... I could eventually have
>millions of files and I'd hate to be recoding everything to use a new
>directory structure, then trying to shift all those files around when I
>already had tens or hundreds of thousands of files stored.


Look at the way a news server is set up. Lots and Lots of directories.

>A: How to design so it can easily be spread over multiple disks. Seems
>subdirectories based on the initial letters of the filenames would
>work.


Yes, but there are other problems. You are posting from a search engine -
did you try looking there first? For a rather interesting starting point,
get to the 'advanced search' section of google groups, and look in the
'comp.os.linux.*' hierarchy, for the _Subject:_

9Gbyte SCSI disc as boot disc with 1106 cylinders
All 16 messages in topic - view as tree
From: Peter Loibl - view profile
Date: Wed, Oct 22 1997 12:00 am
Email: Peter Loibl <p...@daxware.de>
Groups: comp.os.linux.hardware, comp.os.linux.development.system,
comp.os.linux.help, comp.os.linux.setup

It's a fairly long thread - read especially the stuff from Stephen Tweedie.
That will suggest other subjects to investigate. But it is doable,
because Google is already doing so using Linux.

Old guy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-18-2008, 06:58 PM
Doesn't Work At McDonalds
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

Moe Trin wrote:
> >So, my new web server will be set-up soon and I'm going to be running a
> >suite of applications that will let people upload files.

>
> Hope you are filtering lest you become a WareZ server


No way to upload WareZ with the mechanism offered.

> Look at the way a news server is set up. Lots and Lots of directories.


Thanks. A pointer in a good direction.

> For a rather interesting starting point,
> get to the 'advanced search' section of google groups, and look in the
> 'comp.os.linux.*' hierarchy, for the _Subject:_
>
> 9Gbyte SCSI disc as boot disc with 1106 cylinders

[snip]
> It's a fairly long thread - read especially the stuff from Stephen Tweedie.
> That will suggest other subjects to investigate. But it is doable,
> because Google is already doing so using Linux.


Thanks, another good pointer.

- Greg

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-18-2008, 06:58 PM
Juha Laiho
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

"Doesn't Work At McDonalds" <burgerguy@gmail.com> said:
>So, my new web server will be set-up soon and I'm going to be running a
>suite of applications that will let people upload files. The files
>will be have a description stored in a database and be given a random
>filename equal to their unique ID in the database before they're
>stored.
>
>With the filename being a random sequence of letters and numbers, the
>maximum number of files I can store is limited to 36 ^ filename length.
> At just 8 chars, it's over 2 trillion. I'm not worried there.
>
>So I'm trying to figure out how I set up the directory structure for
>maximum expandability and maximum efficiency. If my new site is
>unsuccessful, it won't matter. But if it is... I could eventually have
>millions of files and I'd hate to be recoding everything to use a new
>directory structure, then trying to shift all those files around when I
>already had tens or hundreds of thousands of files stored.
>
>What I'm trying to figure out is:
>
>A: How to design so it can easily be spread over multiple disks. Seems
>subdirectories based on the initial letters of the filenames would
>work. For example, /home/myusername/stuff/A, /home/myusername/stuff/B,
>and /home/myusername/stuff/1, could each be mounted to a different
>physical drive in an external array, giving me 36 * average drive size
>expandability. And because the filenames are randomly generated, the
>distribution should be fairly even.


Could use that -- but also, could exceed by far the limits of single disk
by using a real disk subsystem (something that hides individual disks
from the server, and just serves capacity - possibly even fault-tolerant
capacity). These things also can handle load balancing across disks.
Or perhaps a combination of thw two.

>B: How to design for fastest reads and writes. What I'm wondering is
>where the tipping point is in terms of number of files or subdirs
>degrading write/read/seek speed?


.... but later on you told that reads are the majority of accesses.

>Am I better off putting 360,000 files in one directory, or subdividing
>that into 36 subdirectories of 10,000 files each, or perhaps subdividing
>further into 1296 subdirectories (36 subdirectories with 36 subdirectories
>within them) of 278 files each?


You might look at how the web caches, such as Squid, are doing this.

>Technically, with an 8-character filename, I have over two trillion
>filenames available and could have over two trillion subdirectories,
>each 11 levels deep (for example...
>/home/myusername/stuff/1/T/6/Y/B/0/P/R/1T6YB0PR.file). But since I'd
>have to do a series of mkdir commands each time I stored a file, that
>could slow performance.


.... but writes were just a fraction of the load, right?

Anyway, that example is by far overdoing the directory hashing - esp.
the last two directory components: you'd have a directory with 36
subdirectories, each with just a single file. What Squid does (from
memory), is something like
..../1T/6Y/B0/1T6YB0PR.file

.... wham! Massive reduction in directory names - and still keeping
sizes of single directories in sane limits (up to 36*36 elements).
Also, your worry of directory creation speed largely goes away, as
there'd be at most three levels to create.

One thing you could do: measure. Write a proggy to create a directory
structure, and a proggy to randomly read it (run several in parallel),
and time the execution.

Then change the structure, and measure again, with similar load.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-18-2008, 06:58 PM
Matt Giwer
 
Posts: n/a
Default Re: Most Efficient Directory Structure?

Doesn't Work At McDonalds wrote:
> H.Xu wrote:


>>Why not store files themselves in a database? Then you do not need to
>>worry about too many files. You may worry about backup though.


> First, it's an automatic performance hit. Retrieving the file from the
> database and serving it programatically requires more CPU and disk
> activity than directly linking to the file. That means slower serving
> and more wear and tear on the server.


While I think I agree with that it is not much of a hit. If that hit is
significant you should have more than one server.

> Second, I've had a very large database and the larger it got, the more
> maintenance had to be done on it to keep things flowing smoothly.


Of course always a consideration and worse with more servers.

> Third, IIRC, most filesystems have a maximum size for a single file and
> the database "data" is kept in one file per table. So, if that limit
> is 4 gigs, then I'd have to create a new table each time I started
> approaching the 4 gig limit. On a 500gb drive with 400 gigs allocated
> to files, that would require distributing the files across 100 tables.
> The mechanisms needed to manage that would create additional overhead
> to slow things down.


Can one ask just what kinds of files you intend to serve with the huge numbers
you are talking about? It sounds like DVDs. Are you doing worst case planning or
are these credible requirements? It is always possible to come up with an even
worse worst case.

I would be surprised if you can come up with a "best" solution for files from 2
bytes to 2GB. If you can, publish. If you have a usual file size and expect a
few outlyers then set up two file systems even if on different drives on a
single server.

--
Test question: Israel's war on Lebanon lasted 34 days. From the beginning
Israel said 33. In the middle of September 2006, Israel has the length down
to 30 days. How long will it take to get down to six days?
-- The Iron Webmaster, 3711
nizkor http://www.giwersworld.org/nizkook/nizkook.phtml
Iraqi democracy http://www.giwersworld.org/911/armless.phtml a3
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520