创建一个空文件以强制虚拟机管理程序增长真实文件系统

发布于 2024-10-04 20:35:54 字数 1179 浏览 5 评论 0原文

我正在使用 Amazon EC2 和 CloudLayer 等云计算机。高清性能是瓶颈。

我从 CloudLayer 得到的建议之一是使用 5GB 的大文件来扩展我的文件系统,这样他们就不必在我每次写入磁盘时都扩展它。我编写了这个 Powershell 脚本,但因为这会创建空值,所以我不确定虚拟机管理程序是否真的会增长底层文件系统文件。

我如何验证它确实有效?

#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()
}

他们的解释:

如果您尝试过,CCI 使用平面文件来存储文件系统内容 (.vdx)在您自己的工作站上进行虚拟化,这可能看起来很熟悉。创建 VM 时,您指定最大虚拟驱动器大小,但是平面文件或 .vdx 仅与操作系统安装所需的空间一样大,并且平面文件将随着您需要更多空间而相应增长。

当只有少量虚拟主机需要在平面文件上分配额外空间,然后写入时会非常快速且透明地进行,但是,当写入共享存储介质时,会分配额外空间在将内容写入磁盘之前对读写性能的影响更大。

您可以通过在平面文件上预先分配空间来提高性能,这是通过写入大文件来实现的当系统使用率较低(大约 5GB)时,将其导出到驱动器,然后删除刚刚创建的文件。这将使平面文件的大小与测试文件成正比,删除它可以再次释放空间以供使用。

现在,当您使用存储介质时,虚拟机管理程序不需要浪费时间分配额外的 空间。 SAN 上的空间,同时尝试写入虚拟驱动器。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事和酒 2024-10-11 20:35:55

如果您担心确保文件已填充某些内容,您可以轻松初始化字节数组,.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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文