2

On my Linux vServer the inodes are limited (e.g. 250.000). I found that an Yii2 installation requires quite a lot of inodes. The number of inode is roughly the number of files and directories.

The number of inodes used in the current directory and its subdirectories can be determined with

find .  -xdev -printf '%h\n' | sort | uniq -c | awk '{total = total + $1}END{print total}'

An average of my Yii2 projects is about 30k inodes. There are not much in files in ./web/assets, in the ./runtime or ./web/images folders. Most of the inodes are used in the ./vendor directory.

So the number of my Yii2 projects is limited to 8 projects.

What can I do to reduce inode usage in Yii2 projects?

WeSee
  • 3,158
  • 2
  • 30
  • 58
  • I think part of the solution lies in Yii2 or composer configurations. And maybe in some lines of code to add, too. But I'll try a cross post, too. Thanks @aneroid – WeSee Feb 27 '16 at 13:12
  • I'd like to see in SO any kind of lines of code e.g. to clean up files or other best practices for handling inodes in applications. In [Serverfault](http://serverfault.com) I expect the configuration related topics to be discussed. – WeSee Feb 27 '16 at 13:28
  • Imho, SO could be a great site for "best practices" but that in itself is why it wouldn't be the right place for it :-) These would vary by user preferences, changing industry norms, etc. Hence, you'd be better of reading about best practices in books, blogs, articles, etc. and then determining for yourself which one you want to follow. Btw, I'm un-doing my close+migrate vote. Misunderstood the intent. – aneroid Feb 27 '16 at 13:32
  • Thanks. Maybe the solution gets a general Yii2 framework issue later since vServer with inode limits are a common production environment for Yii2 applications. – WeSee Feb 27 '16 at 13:36
  • Do you specifically want to reduce already used inodes or limit Yii2 inode usage? If it's the first one, [check out](http://stackoverflow.com/a/9387415/1431750) these [two](http://stackoverflow.com/a/347633/1431750) answers. – aneroid Feb 27 '16 at 18:40
  • Thanks @aneroid for the links but they are mostly about locating inodes usage on the disk rather than reducing inode in the Yii2 application. Are there Yii2 specific techniques to reduce inode usage (e.g. reduce Yii2-caching or change AppAsset strategy or cleaning up asset/runtime directories periodically)? – WeSee Feb 29 '16 at 13:41

1 Answers1

1

Assuming you have root in your Linux vServer, you can embed a new filesystem in a single file and mount it. Such a file would take only a single inode in the parent filesystem while the number of inodes within the image is up to you.

# dd if=/dev/zero of=myfs bs=1MB count=512
512+0 records in
512+0 records out
512000000 bytes (512 MB) copied, 4.10134 s, 125 MB/s
# losetup --find --show `pwd`/myfs
/dev/loop0
# mkfs -t ext4 -i 1024 /dev/loop0
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done
Creating filesystem with 500000 1k blocks and 500464 inodes
Filesystem UUID: fef5ab29-8991-4f99-8a27-80b4d11b3133
Superblock backups stored on blocks:
        8177, 24529, 40881, 57233, 73585, 204401, 220753, 400625

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

# mount /dev/loop0 /mnt
# df -i | sed -n '1p;/mnt/p'
Filesystem     Inodes  IUsed  IFree IUse% Mounted on
/dev/loop0     500464     11 500453    1% /mnt

Here, I chose ext4 and set the bytes-per-inode, -i, to its minimum value, giving the largest inode count, 500464, for 512MiB on ext4.

You could make multiple filesystems this way, one for each project, or make a much larger one with many more inodes.

To mount the image at the next reboot, add a line to /etc/fstab.

dan4thewin
  • 1,134
  • 7
  • 10
  • Wow, what crazy idea to embed a filesystem into the vServer! +1 for that. Please help me with the downsides of the solution since I don't have any experience with creating filesystems like that: What about persisting the filesystem during reboot? How about performance? – WeSee Feb 29 '16 at 13:31
  • I do not check the answer button yet since this solution would require bigger changes in the Yii2 applications and I'd like to reduce inodes in the existing Yii2 applications first. – WeSee Feb 29 '16 at 13:34
  • 1
    You handle persistence by adding a line for the filesystem to `/etc/fstab`. I think any performance differences would be negligible. Downsides - you could potentially backup your data twice. The images are a fixed size, though you could always create a new one and then copy data over to effect a size change. – dan4thewin Feb 29 '16 at 17:23