mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-06 21:12:55 +00:00
After enabling autoscaling, we faced the issue that customers are not able to get the number of CPUs they use at this moment. Therefore I've added these two options: 1. Postgresql function to allow customers to call it whenever they want 2. `compute_ctl` endpoint to show these number in console
36 lines
694 B
C
36 lines
694 B
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* neon_utils.c
|
|
* neon_utils - small useful functions
|
|
*
|
|
* IDENTIFICATION
|
|
* contrib/neon_utils/neon_utils.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#else
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include "postgres.h"
|
|
#include "fmgr.h"
|
|
|
|
PG_MODULE_MAGIC;
|
|
|
|
PG_FUNCTION_INFO_V1(num_cpus);
|
|
|
|
Datum
|
|
num_cpus(PG_FUNCTION_ARGS)
|
|
{
|
|
#ifdef _WIN32
|
|
SYSTEM_INFO sysinfo;
|
|
GetSystemInfo(&sysinfo);
|
|
uint32 num_cpus = (uint32) sysinfo.dwNumberOfProcessors;
|
|
#else
|
|
uint32 num_cpus = (uint32) sysconf(_SC_NPROCESSORS_ONLN);
|
|
#endif
|
|
PG_RETURN_UINT32(num_cpus);
|
|
}
|