Exemplo n.º 1
0
Arquivo: server.c Projeto: cobblau/JFF
int main(int argc, char *argv[])
{
    int  listen_fd;


    if(server_setup(argc, argv) == ERROR) {
        jff_log(JFF_ERROR, "server setup error");
        return -1;
    }

    if ((listen_fd = tcp_listen(PORT)) == -1) {
        return -1;
    }

    server.listen_fd = listen_fd;

    server.ncpus = sysconf(_SC_NPROCESSORS_CONF);

    if (workers_init(&server) != 0) {
        jff_log(JFF_ERROR, "init workers error!\n");
        goto finish;
    }

    /*
    if (workers_wakeup() != 0) {
        jff_log(JFF_ERROR, "create wokers error!\n");
        goto finish;
    }
    */

    if (workers_fun() != 0) {
        jff_log(JFF_ERROR, "whimp wokers error!\n");
        goto finish;
    }

    if (workers_off_duty() != 0) {
        jff_log(JFF_ERROR, "wokers off duty error!\n");
        goto finish;
    }

    if (workers_destroy() != 0) {
        jff_log(JFF_ERROR, "wokers off duty error!\n");
        goto finish;
    }

 finish:
    close(listen_fd);

    return 0;
}
Exemplo n.º 2
0
rstatus_t
init_server(struct instance *nci)
{
    rstatus_t status;
    uint32_t i;
    redisDb *db;

    vr_conf *conf;

    conf = conf_create(nci->conf_filename);

    server.pid = getpid();
    server.configfile = getAbsolutePath(nci->conf_filename);
    server.hz = 10;
    server.dbnum = 16;
    array_init(&server.dbs, server.dbnum, sizeof(redisDb));
    server.pidfile = nci->pid_filename;
    server.executable = NULL;
    server.activerehashing = CONFIG_DEFAULT_ACTIVE_REHASHING;
    get_random_hex_chars(server.runid, CONFIG_RUN_ID_SIZE);
    server.arch_bits = (sizeof(long) == 8) ? 64 : 32;
    server.requirepass = NULL;

    server.starttime = time(NULL);

    server.maxclients = conf->max_clients;
    server.maxmemory = conf->maxmemory == CONF_UNSET_NUM ? 0 : conf->maxmemory;
    server.maxmemory_policy = CONFIG_DEFAULT_MAXMEMORY_POLICY;

    server.client_max_querybuf_len = PROTO_MAX_QUERYBUF_LEN;

    server.commands = dictCreate(&commandTableDictType,NULL);
    populateCommandTable();
    server.delCommand = lookupCommandByCString("del");
    server.multiCommand = lookupCommandByCString("multi");
    server.lpushCommand = lookupCommandByCString("lpush");
    server.lpopCommand = lookupCommandByCString("lpop");
    server.rpopCommand = lookupCommandByCString("rpop");
    server.sremCommand = lookupCommandByCString("srem");
    server.execCommand = lookupCommandByCString("exec");

    for (i = 0; i < server.dbnum; i ++) {
        db = array_push(&server.dbs);
        redisDbInit(db);
    }
    
    server.monitors = listCreate();

    server.loading = 0;

    server.lua_timedout = 0;

    server.aof_state = AOF_OFF;

    server.stop_writes_on_bgsave_err = 0;

    server.ready_keys = listCreate();

    server.slowlog = listCreate();
    server.slowlog_entry_id = 0;
    server.slowlog_log_slower_than = -1;
    server.slowlog_max_len = CONFIG_DEFAULT_SLOWLOG_MAX_LEN;

    server.stat_peak_memory = 0;

    server.system_memory_size = zmalloc_get_memory_size();

    server.rdb_child_pid = -1;
    server.aof_child_pid = -1;

    server.hash_max_ziplist_entries = OBJ_HASH_MAX_ZIPLIST_ENTRIES;
    server.hash_max_ziplist_value = OBJ_HASH_MAX_ZIPLIST_VALUE;
    server.list_max_ziplist_size = OBJ_LIST_MAX_ZIPLIST_SIZE;
    server.list_compress_depth = OBJ_LIST_COMPRESS_DEPTH;
    server.set_max_intset_entries = OBJ_SET_MAX_INTSET_ENTRIES;
    server.zset_max_ziplist_entries = OBJ_ZSET_MAX_ZIPLIST_ENTRIES;
    server.zset_max_ziplist_value = OBJ_ZSET_MAX_ZIPLIST_VALUE;
    server.hll_sparse_max_bytes = CONFIG_DEFAULT_HLL_SPARSE_MAX_BYTES;

    vr_replication_init();
    
    createSharedObjects();

    status = master_init(conf);
    if (status != VR_OK) {
        log_error("init master thread failed");
        return VR_ERROR;
    }

    server.port = master.listen->port;
    
    status = workers_init(nci->thread_num);
    if (status != VR_OK) {
        log_error("init worker threads failed");
        return VR_ERROR;
    }

    log_debug(LOG_NOTICE, "mem_alloc_lock_type: %s", malloc_lock_type());
    log_debug(LOG_NOTICE, "malloc lib: %s", VR_MALLOC_LIB);

    return VR_OK;
}