The neon_utils extension
Monitor how Neon's Autoscaling feature allocates compute resources
The neon_utils
extension provides a num_cpus()
function you can use to monitor how Neon's Autoscaling feature allocates vCPU in response to workload. The function returns the current number of allocated vCPUs.
For information about Neon's Autoscaling feature, see Autoscaling.
neon_utils
extension
Install the Install the neon_utils
extension by running the following CREATE EXTENSION
statement in the Neon SQL Editor or from a client such as psql
that is connected to Neon.
For information about using the Neon SQL Editor, see Query with Neon's SQL Editor. For information about using the psql
client with Neon, see Connect with psql.
num_cpus()
function
Use the In Neon, computing capacity is measured in Compute Units (CU). One CU is 1 vCPU and 4 GB of RAM, 2 CU is 2 vCPU and 8 GB of RAM, and so on. The amount of RAM in GB is always 4 times the number of vCPU. A Neon compute can have anywhere from .25 to 10 CU.
Defining a minimum and maximum compute size for your compute, as shown below, enables autoscaling.
As your workload changes, computing capacity scales dynamically between the minimum and maximum settings defined in your compute configuration. To retrieve the number of allocated vCPU at any point in time, you can run the following query:
For autoscaling configuration instructions, see Compute size and autoscaling configuration.
Limitations
The following limitations apply:
- The
num_cpus()
function does not return fractional vCPU sizes. The Autoscaling feature can scale by fractional vCPU, but thenum_cpus()
function reports the next whole number. For example, if the current number of allocated vCPU is.25
or.5
, thenum_cpus()
function returns1
. - The
num_cpus()
function only works on computes that have the Autoscaling feature enabled. Running the function on a fixed size compute does not return a correct value.
neon_utils
and pgbench
Observe autoscaling with The following instructions demonstrate how you can use the num_cpus()
function with pgbench
to observe how Neon's Autoscaling feature responds to workload.
Prerequisites
- Ensure that autoscaling is enabled for your compute. For instructions, see Compute size and autoscaling configuration. The following example uses a minimum setting of 0.25 Compute Units (CU) and a maximum of 4.
- The pgbench utility.
Run the test
-
Install the
neon_utils
extension: -
Create a
test.sql
file with the following queries: -
To avoid errors when running
pgbench
, initialize your database with the tables used bypgbench
. This can be done using thepgbench -i
command, specifying the connection string for your Neon database. You can obtain a connection string from the Connection Details widget on the Neon Dashboard. -
Run a
pgbench
test with yourtest.sql
file, specifying your connection string:The test produces output similar to the following on a compute set to scale from 0.25 to 4 CUs.
-
Call the
num_cpus()
function to retrieve the current number of allocated vCPU.
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more detail, see Getting Support.
Last updated on