Exemple #1
0
struct network_server_s *
network_server_init(void)
{
	int wakeup[2];
	guint count, maxfd;
	struct network_server_s *result;

	wakeup[0] = wakeup[1] = -1;
	if (0 > pipe(wakeup)) {
		GRID_ERROR("PIPE creation failure : (%d) %s", errno, strerror(errno));
		return NULL;
	}
	shutdown(wakeup[0], SHUT_WR);
	shutdown(wakeup[1], SHUT_RD);
	fcntl(wakeup[0], F_SETFL, O_NONBLOCK|fcntl(wakeup[0], F_GETFL));

	count = _server_count_procs();
	maxfd = _server_get_maxfd();

	result = g_malloc0(sizeof(struct network_server_s));
	result->flag_continue = ~0;
	result->stats = grid_stats_holder_init();

	clock_gettime(CLOCK_MONOTONIC_COARSE, &result->now);

	result->queue_events = g_async_queue_new();
	result->queue_monitor = g_async_queue_new();

	result->endpointv = g_malloc0(sizeof(struct endpoint_s*));
	g_mutex_init(&result->lock_threads);
	result->workers_max_idle_delay = SERVER_DEFAULT_MAX_IDLEDELAY;
	result->workers_minimum = count;
	result->workers_minimum_spare = count;
	result->workers_maximum = SERVER_DEFAULT_MAX_WORKERS;
	result->cnx_max_sys = maxfd;
	result->cnx_max = (result->cnx_max_sys * 99) / 100;
	result->cnx_backlog = 50;
	result->wakeup[0] = wakeup[0];
	result->wakeup[1] = wakeup[1];
	result->epollfd = epoll_create(4096);

	// XXX JFS : #slots as a power of 2 ... for efficient modulos
	result->workers_active_1 = grid_single_rrd_create(result->now.tv_sec, 32);
	result->workers_active_60 = grid_single_rrd_create(result->now.tv_sec/60, 64);

	result->atexit_max_open_never_input = 3;
	result->atexit_max_idle = 2;
	result->atexit_max_open_persist = 10;

	GRID_INFO("SERVER ready with epollfd[%d] pipe[%d,%d]",
			result->epollfd, result->wakeup[0], result->wakeup[1]);

	return result;
}
Exemple #2
0
static void
test_rrd (void)
{
	struct grid_single_rrd_s *rrd = grid_single_rrd_create(2, 60);
	grid_single_rrd_push(rrd, 3, 0);
	grid_single_rrd_push(rrd, 1000, 0);
	grid_single_rrd_push(rrd, 2, 0);
	grid_single_rrd_destroy(rrd);
}
Exemple #3
0
static gboolean
_init_configless_structures(struct sqlx_service_s *ss)
{
	if (!(ss->server = network_server_init())
			|| !(ss->dispatcher = transport_gridd_build_empty_dispatcher())
			|| !(ss->si = g_malloc0(sizeof(struct service_info_s)))
			|| !(ss->clients_pool = gridd_client_pool_create())
			|| !(ss->gsr_reqtime = grid_single_rrd_create(oio_ext_monotonic_time() / G_TIME_SPAN_SECOND, 8))
			|| !(ss->gsr_reqcounter = grid_single_rrd_create(oio_ext_monotonic_time() / G_TIME_SPAN_SECOND,8))
			|| !(ss->resolver = hc_resolver_create1(oio_ext_monotonic_time() / G_TIME_SPAN_SECOND))
			|| !(ss->gtq_admin = grid_task_queue_create("admin"))
			|| !(ss->gtq_register = grid_task_queue_create("register"))
			|| !(ss->gtq_reload = grid_task_queue_create("reload"))) {
		GRID_WARN("SERVICE init error : memory allocation failure");
		return FALSE;
	}

	return TRUE;
}