开发者

Creating an empty file to force the hypervisor to grow the real filesystem

I'm using cloud computers like Amazon EC2 and CloudLayer. HD performance is the bottleneck.

One of the tip I got from CloudLayer was to grow my file system with a big 5GB file so that they don't have to grow it every time I write to the disk. I wrote this Powershell script, but because this create null values, I'm not sure if the hypervisor will really grow the underlying filesystem file.

How can I validate that it did work?

#Find all local drives
get-psdrive -PSProvider 'FileSystem' | where {$_.Root -like '?:\'} | foreach {
    $msg1 = "Drive " + $_.Name + " has " + $_.Free + " bytes"
    Write-Host $msg1        

    #Create a file the size of the empty space on the drive.
    $fileNameAndPath = $_.Root + 'BIG_TEMP_FILE_DELETE_THIS.dat'
    $f = new-object System.IO.FileStream $fileNameAndPath, Create, ReadWrite
    $f.SetLength($_.Free)
    $f.Close()
}

Their explanation:

The CCIs use a flat-file to store the filesystem contents (.vdx) if you have experimented with virtualization on your own workstation this may look familiar. When the VM is created you specify a maximum virtual drive size, however the flat-file or .vdx is only as large as the space required by the OS installation and the flat-file will grow accordingly as you need more space.

When there is only a small number of virtual hosts to work with allocating additional space on the flat-file and then writing to it happens very quickly and transparently, however, when writing to a shared storage medium, allocating the additional space before writing the contents to the disk has a much greater impact on the read and write performance.

You can increase the performance by pre-allocating space on the flat-file, this is accomplished by writing a large file out to the drive when the system is under light usage (about 5GBs) and then removing the file you just created. This will grow the flat-file an amount proportional to the test file and removing it frees up the space again for usage.

Now when you use the storage medium, the hypervisor does not need to waste time allocating additional space on the SAN while attempting t开发者_Python百科o write to your virtual drive at the same time.


If you are worried about making sure the file is filled with something, you can easily initialize a byte array and .NET will guarantee that the initialized bytes are set to 0. You can use that to write out actual data to the disk.

# write 4K worth of data at a time
$bufSize = 4096
$bytes = New-Object byte[] $bufSize
$file = [System.IO.File]::Create("C:\big.raw")
# write the first block out to accommodate integer division truncation
$file.Write($bytes, 0, $bufSize)
for ($i = 0; $i -lt $_.Free; $i = $i + $bufSize) { $file.Write($bytes, 0, $bufSize) }
$file.Close()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜