# Page caching and maximum number of files per directory

**URL:** <https://www.ruby-forum.com/t/page-caching-and-maximum-number-of-files-per-directory/140898>\
**Category:** Rails\
**Created:** [June 19, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/page-caching-and-maximum-number-of-files-per-directory/140898 "2008-06-19T16:15:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [June 19, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/page-caching-and-maximum-number-of-files-per-directory/140898/1 "2008-06-19T16:15:53Z")

</div>

I am using ubuntu with ext3 file system.

How many files can I store inside a directory?

Is it an effect way to save all 100,000 cached files inside one  
directory if it is allowed? Or will it be worth arranging these files  
into sub directories to reduce the file size, to speed up web page  
request?

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [June 19, 2008, 10:56pm UTC](https://www.ruby-forum.com/t/page-caching-and-maximum-number-of-files-per-directory/140898/2 "2008-06-19T22:56:05Z")

</div>

Nanyang Z. wrote:

> I am using ubuntu with ext3 file system.
> 
> How many files can I store inside a directory?
> 
> Is it an effect way to save all 100,000 cached files inside one  
> directory if it is allowed? Or will it be worth arranging these files  
> into sub directories to reduce the file size, to speed up web page  
> request?

I cache fragments with an explicit path for the type of fragment cached  
and model.  
Has made it easy to clear out some fragments while keeping other if I  
change the rendering of a certain piece. Like:

/show/project/ \<- individual project fragments go here  
/show/scenario/ \<- scenario fragments go here  
/related/project/ \<- “relations” fragments for projects go here  
/related/scenario/ \<- “relations” fragments for scenario go here

along with keeping the file counts per folder lower, if I change the  
“show” rendering of a model, or all models, I have a specific tree to  
prune to dump those cached fragments. Same goes for the “related” tree  
(which is comparatively expensive to generate versus the “show”  
fragment).

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [June 20, 2008, 5:21am UTC](https://www.ruby-forum.com/t/page-caching-and-maximum-number-of-files-per-directory/140898/3 "2008-06-20T05:21:48Z")

</div>

Ar Chron wrote:

> I cache fragments with an explicit path for the type of fragment cached  
> and model.  
> Has made it easy to clear out some fragments while keeping other if I  
> change the rendering of a certain piece.

I think it is a good solution for you.

In my case, I want to cache the whole page, and there will be more than  
100,000 page, which sharing a common layout. I want to know if I should  
put all the cached files inside one single directory. By default, rails  
will do so. But I am worry it may go beyond the limit of the file system  
to store so many files, and to put too many files inside one directory  
may make fetching one file take more time.

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [June 20, 2008, 7:08am UTC](https://www.ruby-forum.com/t/page-caching-and-maximum-number-of-files-per-directory/140898/4 "2008-06-20T07:08:30Z")

</div>

Hiya,

100,000 files in a directory sounds a lot.

In ext3 I think the number of files is irrelevant to directories. Its a  
matter of the drive itself, size of inodes and size of all the files,  
etc.

I seem to remember seeing a presentation from Joyent where they found  
they need a limit of 32,000 files in a dir, from a practical point of  
view - could be wrong though I can’t find it at the moment.

[ext3 - Wikipedia](http://en.wikipedia.org/wiki/Ext3) for more info.

If its not to much effort, it would be safer to split them into smaller  
chunks.

Matt S.

> **[internetschminternet.com is almost here!](http://www.internetschminternet.com)**
>
> The owner of this domain has not yet uploaded their website.

---

<div class="post-metadata">

**Author:** ![xain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/82dd89/32.png) [@xain](https://www.ruby-forum.com/u/xain)\
**Post date:** [June 20, 2008, 8:22am UTC](https://www.ruby-forum.com/t/page-caching-and-maximum-number-of-files-per-directory/140898/5 "2008-06-20T08:22:29Z")

</div>

Matt S.1 wrote:

> In ext3 I think the number of files is irrelevant to directories.

So, I think the directory on my server can hold 100,000 per directory.

> If its not to much effort, it would be safer to split them into smaller  
> chunks.

These cached files are named by article titles, so it won’t be too easy,  
and that is why I want to know if it worth the effort.

BTW, in your opinion, how many will be a nice “smaller” size?
