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.
Install the neon_utils extension
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.
Use the num_cpus() function
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 7 CU.
Defining a minimum and maximum compute size for your compute endpoint, as shown below, enables Autoscaling.

As your workload changes, computing capacity scales dynamically between the minimum and maximum settings defined in your compute endpoint 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.25or.5, thenum_cpus()function returns1.
- The num_cpus()function only works on compute endpoints that have the Autoscaling feature enabled. Running the function on a fixed size compute endpoint does not return a correct value.
Observe Autoscaling with neon_utils and pgbench
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 endpoint. 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_utilsextension:
- 
Create a test.sqlfile with the following queries:
- 
To avoid errors when running pgbench, initialize your database with the tables used bypgbench. This can be done using thepgbench -icommand, 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 pgbenchtest with yourtest.sqlfile, specifying your connection string:The test produces output similar to the following on a compute endpoint 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 the Neon community forum to ask questions or see what others are doing with Neon. Neon Pro Plan users can open a support ticket from the console. For more detail, see Getting Support.
Last updated on