PHP Memcache 中的压缩有何作用?

发布于 2024-08-18 09:33:43 字数 434 浏览 2 评论 0原文

在 PHP.net 上,我正在查看 Memcache::set 函数它有这个可选标志来使用压缩...

使用MEMCACHE_COMPRESSED来存储 项目压缩(使用 zlib)。

$memcache_obj->set('var_key',
                   'some really big variable',
                    MEMCACHE_COMPRESSED,
                    50);

我很好奇,如果只使用更少的空间,这样做有什么好处?看起来这会减慢进程?

On PHP.net I am looking at the Memcache::set function and it has this optional flag to use compression...

Use MEMCACHE_COMPRESSED to store the
item compressed (uses zlib).

$memcache_obj->set('var_key',
                   'some really big variable',
                    MEMCACHE_COMPRESSED,
                    50);

I am curious, what would be the benefit of this, just using less space? It seems like this would slow the process down?

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

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

发布评论

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

评论(3

飘然心甜 2024-08-25 09:33:43

在运行 PHP 的服务器上压缩和解压缩可能会很快 - 根据您的网络和服务器上的负载,它可能比从 memcached 传输更多(未压缩)数据更快通过网络的服务器。

压缩数据还意味着在 memcached 服务器上使用更少的内存。

通常,您必须在 CPU、网络和 RAM 之间进行选择,并且必须考虑您的服务器和网络、它们的负载和可用资源,才能做出决定。

在您的特定情况下,“最快”的解决方案是什么?只有您才能知道……唯一了解的方法可能是在“真实条件”下测试这两种解决方案。

另外,memcached 条目不能大于 1 MB;我认为,在某些方面,压缩可以帮助将大于 1 MB 的条目(尚未压缩时)放入 memcached 中。

Compressing and decompressing on the servers that are running PHP can be quick -- depending on your network and the load on your servers, it can be quicker than transferring more (not compressed) data to and from the memcached servers via the network.

Compressing your data also means using less memory on the memcached servers.

As often, you have to choose between CPU, network, and RAM -- and you have to take into consideration your servers and network, their load, and available resources, to be able to decide.

What will be the "quickiest" solution in your particular situation ? Only you can tell... And the only way to know is probably by testing both solutions in "real conditions".

Also, memcached entries cannot be bigger than 1 MB ; I suppose, in some ways, that compression can help put entries a bit bigger than 1 MB (when not compressed yet) into memcached.

樱娆 2024-08-25 09:33:43
  1. memcached 可用于在机器之间保留分布式缓存。在这种情况下,缓存的更新需要通过网络或机器之间的其他连接发送。压缩减少了需要发送的数据量,从而减少了传输所需的时间,从而提高了系统性能。
  2. 即使在一台主机内,压缩也比将内存页面交换到磁盘或从磁盘交换内存页面要快几个数量级,因此,如果您由于内存不足而进行交换,压缩将减少需要交换的数量,从而提高性能。在正确的条件下,压缩可能会充分减少数据的大小,以便您根本不需要交换 - 这是性能上的巨大胜利。
  1. memcached can be used to keep a distributed cache between machines. In that case updates to the cache will need to be sent through the network or other connection between the machines. Compression reduces the amount of data that needs to be sent therefore reduce time needed to transfer and can therefore improve system performance.
  2. even within one host, compressing is orders of magnitude faster than swapping memory pages to/from disks, so if you are swapping due memory shortage, compression will reduce the amount that needs to be swapped, and thereby improve performance. Under the right corner conditions, compression might reduce the size of data enough so that you don't have to swap at all - a big win in performance.
旧人哭 2024-08-25 09:33:43

你是对的,这是占用更少的空间占用更多CPU周期之间的权衡。

您也可以选择 RAM 或 CPU 哪种资源对您来说更宝贵。

You're right, it's a trade off between taking up less space or eating up more CPU cycles.

You've too choose which resource is more precious to you, RAM or CPU.

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