Exemplo n.º 1
0
static PyObject* Storage_new(PyTypeObject *type, PyObject *args, PyObject *kwdict) {

  StorageObject* self = (StorageObject *)type->tp_alloc(type, 0);

  if (self != NULL) {
    self->cdb = cdb_new();

    if (self->cdb == NULL) {
      Py_DECREF(self);
      return NULL;
    }

    self->header = PyDict_New();

    if (self->header == NULL) {
      Py_DECREF(self);
      return NULL;
    }

    self->statistics = Py_None;
  }

  return (PyObject *)self;
}
Exemplo n.º 2
0
Arquivo: nastd.c Projeto: bjc/nastd
static int
init_daemon()
{
	sigset_t sigmask;

	log_open();
	if (cdb_new())
		return -1;
	mysqldb_new();
	if (memdb_new())
		return -1;

	/*
	 * Turn off SIGPIPE. The calls to write() will return fine with
	 * it off, and this means we don't have to do any signal mojo.
	 */
	(void)sigemptyset(&sigmask);
	(void)sigaddset(&sigmask, SIGPIPE);
	(void)sigprocmask(SIG_BLOCK, &sigmask, NULL);

	/* Now we daemonise. */
	switch (fork()) {
	case 0:
		setsid();
		close(STDIN_FILENO);
		close(STDOUT_FILENO);
		break;
	case -1:
		log_err("Couldn't fork into daemon: %s.", strerror(errno));
		return -1;
	default:
		exit(0);
	}

	return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    int thread_num = 2;
    int record_num = 10000000;
    char *db_path = NULL;
    printf("Usage: %s db_path [record_num] [thread_num]\n", argv[0]);
    if (argc >= 2)
        db_path = argv[1];
    else
        return -1;

    if (argc >= 3)
        record_num = atoi(argv[2]);
    if (argc >= 4)
        thread_num = atoi(argv[3]);

    record_num = record_num < 100? 100: record_num;
    thread_num = thread_num < 1? 1: thread_num;
    srand(time(NULL));

    db = cdb_new();
    cdb_option(db, record_num / 100, 0, 1024000);
    if (cdb_open(db, db_path, CDB_CREAT | CDB_TRUNC) < 0) {
        printf("DB Open err\n");
        return -1;
    }


    optable = prob_table1;
    pthread_t threads[thread_num];
    for(int i = 0; i < thread_num; i++) {
        pthread_create(&threads[i], NULL, test_thread, &record_num);
    }

    int clear_interval = 0;
    while(1) {
        CDBSTAT st;
        cdb_stat(db, &st);
        printf("rnum: %lu, rcnum: %lu, pnum: %lu, pcnum %lu, rlatcy: %u  wlatcy: %u"
                " rh/m: %lu/%lu ph/m: %lu/%lu\n",
                st.rnum, st.rcnum, st.pnum, st.pcnum, st.rlatcy, st.wlatcy,
                st.rchit, st.rcmiss, st.pchit, st.pcmiss);
        if (++clear_interval % 20 == 0)
            cdb_stat(db, NULL);

        if (st.rnum > 0.7 * record_num)
            optable = prob_table2;
        if (st.rnum > 0.9 * record_num)
            optable = prob_table3;

        if (st.rnum < 0.8 * record_num)
            optable = prob_table2;

        if (st.rnum < 0.6 * record_num)
            optable = prob_table1;
        fflush(stdout);
        sleep(1);
    }
    
    return 0;
}