1

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 to write to your virtual drive at the same time.

4

1 回答 1

1

如果您担心文件是否充满了某些东西,您可以轻松地初始化一个字节数组,.NET 将保证初始化的字节设置为 0。您可以使用它来将实际数据写入磁盘。

# 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()
于 2011-03-22T16:39:45.733 回答