From: Jeff Garzik Subject: btest2.c Date: Sat, 14 Nov 2009 18:10:40 -0500 Message-ID: <20091114231039.GA22237@havoc.gtf.org> Mime-Version: 1.0 Return-path: Content-Disposition: inline Sender: hail-devel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: hail-devel@vger.kernel.org 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 #include #include #include #include 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; }