Managing costs for Streamlit in Snowflake

This topic describes billing considerations for Streamlit in Snowflake.

Billing considerations for Streamlit in Snowflake

Streamlit in Snowflake billing is based on the app’s runtime environment and query warehouse. The runtime environment executes the Python code in your Streamlit app and can be either a container or warehouse. The query warehouse executes any SQL queries within your app’s code.

查询仓库

当您的应用程序代码执行 SQL 查询时,这些查询将使用该应用程序的查询仓库。Snowflake 会根据其自身的 AUTO_RESUME 和 AUTO_SUSPEND 值自动恢复和挂起查询仓库。

容器运行时

If your Streamlit app uses a container runtime, you are billed for the usage of the underlying Snowpark Container Services compute pool. In this case, the Streamlit app is a long-running service. The Streamlit server runs continuously on a node of the compute pool, allowing viewers to quickly access the app. Concurrent viewers connect to a single Streamlit server. Only a single app can run on a node in the compute pool; a Streamlit app takes an entire node.

After three days of viewer inactivity, the Streamlit server process ends and Snowflake suspends the compute pool according to its own AUTO_SUSPEND value. If you try to keep a session alive for three days without a new viewer connecting, the app will probably be suspended. It’s a best practice to move long-running computations to another service. For more information about compute pool billing, see Understanding compute cost.

仓库运行时

如果应用程序使用仓库运行时,Snowflake 会在有人访问应用程序时恢复应用程序的代码仓库。每次查看者连接到应用时,都会在代码仓库中启动一个新的 Streamlit 服务器进程,并建立一个 WebSocket 连接。每个并发查看者都连接到各自独立的 Streamlit 服务器,这些服务器均运行在同一个代码仓库中。

一个 WebSocket 连接会保持代码仓库处于活动状态,并在关联查看者最后一次活动后约 15 分钟过期。但是,这可能会受到查看者的浏览器设置和活动的影响。在应用上的鼠标移动被视为活动,可保持 WebSocket 连接处于活跃状态。您可以通过联系 Snowflake 支持部门来更改账户的 WebSocket 超时值。

代码仓库按其活动时间计费。要节省 Credit,您可以执行下列操作之一:

  • Manually suspend the app from Snowsight.
  • Close all browser tabs running the app, or navigate away from the app. This closes the WebSocket connection and allows the warehouse to auto-suspend.
  • Set a custom sleep timer for the app. This automatically suspends the warehouse after a specified period of inactivity. For more information, see Custom sleep timer for a Streamlit app.

For guidelines on selecting a warehouse, see Guidelines for selecting resources in Streamlit in Snowflake.