High swap usage
了解高交换分区使用意味着什么,它可能的原因,以及如何解决它。
🌐 Learn what high Swap usage means, what can cause it, and how to solve it.
换来做什么用的? #
🌐 What is swap for?
除非其他资源(比如内存)紧张,否则高交换通常不成问题。
🌐 High Swap is usually not a problem unless other resources (such as RAM) are constrained.
每个 Supabase 项目都运行在其专用的虚拟机上。虚拟机的底层规范和硬件取决于你的 计算附加组件。如果你的硬件不适合你的工作负载,你可能会遇到高 Swap 使用率。
🌐 Every Supabase project runs on its own dedicated virtual machine. The machine's underlying specs and hardware depend on your compute add-on. If your hardware isn't suitable for your workload, you might experience high Swap usage.
交换区是你实例磁盘的一部分,当可用内存被使用时,操作系统可以使用它。由于它使用的是磁盘,所以访问速度较慢,通常作为最后的选择使用。
🌐 Swap is a portion of your instance's disk that is reserved for the operating system to use when the available RAM is used. As it uses the disk, Swap is slower to access and is generally used as a last resort.
即使你的实例有大量内存,仍然可以使用交换空间。如果是这种情况,不用担心。你的实例可能会尝试“预先交换”,通过把后台进程换出到交换空间来为你的流量腾出内存空间。
🌐 Swap can be used even if your instance has plenty of RAM. If this is the case, do not worry. Your instance might try to "preemptively swap" by swapping background processes to make space for your traffic in RAM.
什么时候高交换值得担心? #
🌐 When is high swap concerning?
如果你的实例正在使用所有可用的内存(即持续使用超过75%),高交换空间是值得关注的。
🌐 High Swap is concerning if your instance is using all of the available RAM (i.e. consistently using more than 75%).
高交换使用率可能会影响你的数据库性能。例如,你可能会看到:
🌐 High Swap usage can affect your database performance. For example, you might see:
- 查询响应更慢。
- 由于经常在内存和磁盘之间交换,导致性能下降。
- 由于频繁交换导致更高的磁盘I/O。
监控你的交换空间 #
🌐 Monitor your swap
你可以使用 Prometheus/Grafana 监控你的资源并设置警报。更多信息请参见 指标指南。
🌐 You can monitor your resources and set up alerts using Prometheus/Grafana. See the metrics guide for more information.
在链接的指南中提供了一个用来获取指标并用 Grafana 可视化的 示例仓库,我们在其中维护了一个 已导出指标列表。
🌐 An example repository to ingest metrics and visualize them with Grafana is provided in the linked guide, where we maintain a list of the exported metrics.
一些有用的监测指标包括(这不是完整列表):
🌐 Some useful metrics to monitor are (this is not an exhaustive list):
node_memory_SwapFree_bytes- 可用交换空间的总字节数。node_disk_io_time_seconds_totalandnode_disk_io_now- 花在磁盘 I/O 上的时间。增加可能间接表明交换过多,但不一定总是这样。node_memory_MemTotal_bytesandnode_memory_MemFree_bytes- 总内存和可用内存。node_vmstat_pswpinandnode_vmstat_pswpout- 已交换进出内存的页数(监控这个指标的尖峰意味着你的实例正在进行交换)。
高交换使用率的常见原因 #
🌐 Common reasons for high swap usage
你在 Supabase 项目中做的每件事都需要计算资源。因此,高 Swap 使用率可能有很多原因。以下是一些常见原因:
🌐 Everything you do with your Supabase project requires compute. Hence, there can be many reasons for high Swap usage. Here are some common ones:
- 查询性能: 你可能会有高读取流量,或者查询会处理大量的磁盘数据(即使你只返回少量数据,也可能发生这种情况)。
- 缺失的索引: 你的数据库可能需要扫描大量数据才能找到所需信息。创建索引可以帮助你的数据库更快地找到数据。查看 索引指南 了解更多信息。
- 不合适的计算资源: 你的 Supabase 项目的计算资源可能不适合你的应用,因为你可能有更多的流量或者运行资源密集型操作。
- 工作负载类型: 你的 Supabase 项目的使用模式可能更多偏向读取,或者涉及大量数据。
- 扩展: 你可能在使用一些对大数据集执行密集操作的扩展。这会增加资源使用量。
解决高交换使用 #
🌐 Solving high swap usage
如果你发现你的内存和交换空间使用率很高,你有三个选择:
🌐 If you find that your RAM and Swap usage are high, you have three options: