linux - socket 并发100+线程,只能发出100个线程的数据
PHP中文网
PHP中文网 2017-04-17 16:30:51
0
1
654

想做http的并发测试。
先建立了一个socket,全局的,和服务器连接上。
然后循环150次,每次建立一个线程,在线程里面去write。
看日志可以看到有write150次,但是只有100次应答,其他的50次,服务端都没收到。
不知道为什么,有哪个大神可以指导下吗。write前后有加锁。
哪怕101次,都只能收到100次。
一定要改成1个线程一个socket吗?

 for(i = 0;i <= user_num;i++)
{
    account[i] = i;
    pthread_create(&tid[i],NULL,uias_send_sms,&account[i]);
    usleep(100);
}
for(i = 0;i <= user_num;i++)
{             
    pthread_join(tid[i],NULL);
}

void uias_send_sms(void arg)

{
    pthread_mutex_lock(&mutex);
    sd = write(sock_fd,http_req,strlen(http_req));
    printf("write sd:%d\n",sd);
    pthread_mutex_unlock(&mutex);

}
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
左手右手慢动作

I’m very surprised. When you do http concurrency testing, there is only one connection. What is your concurrency targeting? The number of connections, or what, there is only one connection, which means that if you have 150 threads writing to the same file descriptor, they will definitely wait for you to fill up the buffer before sending the data, so the number of writes is more than the number of responses

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template