Skip to contentSkip to conversation

btest2.c

DISCUSSION Jeff Garzik 1 participant 1 message Nov 14, 2009

lore
Share & tools
lore
#0 lore raw

This is a simple test to determine memory usage for storing object locations in RAM, indexed by node id, and optimized for
- rapid object id insertion, deletion
- easy method to determine all objects in a single node

Compile with

	gcc -O -Wall `pkg-config glib-2.0 --cflags` -o btest2 btest2.c \
		`pkg-config glib-2.0 --libs`

RAM usage with 10,000,000 objects, 3-way replication: 750 MB RAM usage with 20,000,000 objects, 3-way replication: 1.5 GB

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <glib.h>

enum {
	N_OBJS		= 5 * 1000000,
	N_NID		= 3,
	N_NODES		= 1000,
};

static GHashTable *ht[N_NODES];

static void store_oid_in_node(int node, int oid)

{
	g_hash_table_insert(ht[node], GINT_TO_POINTER(oid), NULL);
}

int main (int argc, char *argv[])

{
	int oid, i, n_objs = 0;
	long x = 1;

	srand(time(NULL));

	/* obtain number of objects for test */
	if (argc > 1)
		n_objs = atoi(argv[1]);
	if (n_objs < 1)
		n_objs = N_OBJS;

	/* create N_NODES hash tables for oid indices */
	for (i = 0; i < N_NODES; i++) {
		ht[i] = g_hash_table_new(g_direct_hash, g_direct_equal);
		if (!ht[i])
			abort();
	}

	/* populate hash tables with N_NID-way simulated replication */
	for (oid = 1; oid < n_objs; oid++)
		for (i = 0; i < N_NID; i++) {
			int node;

			node = rand() % N_NODES;
			store_oid_in_node(node, oid);
		}

	/*
	 * once this prints, you may visit top(1) to determine
	 * memory usage
	 */

	printf("Table build completed.  Begin infinite loop...\n");

	while (1)
		x++;

	return 0;
}