fcgi + leveldb = основной дамп?

в RHEL 5.7 x86_64, когда fcgi и leveldb работают вместе, max_open_files = 4000, он получает ошибку сегментации, когда клиент отправляет запросы. Как?

это не произойдет, если использовать MySQL.

ulimit -n = 655360

GDB:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x52b09940 (LWP 47717)]
0x0000000000000f32 in ?? ()
(gdb) bt
#0  0x0000000000000f32 in ?? ()
#1  0x0000000052b09120 in ?? ()
#2  0x0000000000000000 in ?? ()

Образец кода:

vector<pthread_t> mthread;
const int  THREAD_COUNT = 20;
static int counts[THREAD_COUNT];
pthread_t id[THREAD_COUNT];
int mSocketFd = 0;
vector<int> mfd;
static void *doit(void* arg)
{
int rc, i;
pid_t pid = getpid();
FCGX_Request request;
char *server_name;
FCGX_InitRequest(&request, mSocketFd, 0);
for (;;)
{
static pthread_mutex_t accept_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t counts_mutex = PTHREAD_MUTEX_INITIALIZER;

/* Some platforms require accept() serialization, some don't.. */
pthread_mutex_lock(&accept_mutex);
rc = FCGX_Accept_r(&request);
pthread_mutex_unlock(&accept_mutex);

if (rc < 0)
continue;
server_name = FCGX_GetParam("SERVER_NAME", request.envp);

FCGX_FPrintF(request.out,
"Content-type: text/html\r\n""\r\n""<title>FastCGI Hello! (multi-threaded C, fcgiapp library)</title>""<h1>FastCGI Hello! (multi-threaded C, fcgiapp library)</h1>""Thread %d, Process %ld<p>""Request counts for %d threads running on host <i>%s</i><p><code>",
123, pid, THREAD_COUNT, server_name ? server_name : "?");

sleep(2);

pthread_mutex_lock(&counts_mutex);
//        ++counts[thread_id];
for (i = 0; i < THREAD_COUNT; i++)
FCGX_FPrintF(request.out, "%5d " , counts[i]);
pthread_mutex_unlock(&counts_mutex);

FCGX_Finish_r(&request);
}
cout << "end doit" << endl;

return NULL;
}
class A
{
public:
static void Init()
{
if(NULL == db)
{
leveldb::Options options;
options.create_if_missing = true;
options.max_open_files = 3000;
leveldb::Status status = leveldb::DB::Open(options,"/disk1/leveldb/rand1y", &db);
assert(status.ok());
cout << status.ToString() << endl;
}
}
static  leveldb::DB* Get(){return db;}
private:
A(){}
static leveldb::DB* db;
};
leveldb::DB* A::db = NULL;
void* Get(void *arg)
{
string value("");
int rnd = rand()%100000000;
leveldb::Status status;
string key("");
char str[50];
leveldb::DB* db = A::Get();
stringstream ss;
while(1)
{
rnd = rand()%100000000;
sprintf(str, "test$%d->test$%d", rnd, rnd);
key = str;
status = db->Get(leveldb::ReadOptions(),key, &value);
if(status.IsNotFound())
value = "NotFound!";
}
cout << "Open end" <<endl;
}
int main(){
A::Init();
int err;
for(int i = 0; i < 20; ++i)
{
pthread_t p1;
err = pthread_create(&p1, NULL, Get, NULL);
mthread.push_back(p1);
if(0 != err)
cout << "error" << endl;
}
FCGX_Init();
for (int i = 0; i < THREAD_COUNT; ++i)
{
pthread_create(&id[i], NULL, doit, NULL);
}
for(int i = 0; i < THREAD_COUNT; ++i)
{
pthread_join(id[i], NULL);
}
for(unsigned int i = 0; i < mthread.size(); ++i)
{
pthread_join(mthread[i], NULL);
}
cout << "end " << endl;
return 0;
}

0

Решение

Задача ещё не решена.

Другие решения


По вопросам рекламы [email protected]