LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-14-2016, 07:53 AM   #1
Ec5
LQ Newbie
 
Registered: Nov 2016
Posts: 1

Rep: Reputation: Disabled
Linux performance drawback when networking from two pthreads


my server receives requests in one thread and responds in another. I am using thread pools of pthread-s for both receiving and sending. The performance is not that bad, however...

When I am doing the same algorithm in one thread only(MULTITHREAD not defined) so that both recvs and sends are in the same worker thread, my app runs about 10% better.

Strangely, when I am using separate threads(worker and operation) but include printf in any operation, the performance raises **(yes, raises - not declines)** some 20%. My printfs goes over SSH.(*)

(Packet analyses shows some 100 micros of delay of ACKing responses (not separate ACKs). This delay does not happen with the printfs, neither it happens in a single-thread mode. It seems like SSH triggers something in the TCP stack. )

I tried to use the TCP_QUICKACK option after every recv() but the performance goes down!(**)
I am using Centos7. The application is very concurrent - it is SMB server.


The algorithm is as follow:
one thread that get the message with epoll_wait() and then execute the first worker thread, this thread parse the message and launch the operation thread(create/read/write etc.).

**main thread:**

static void mainThreadBodySocketTransport(CSTransport * transport)
{
struct epoll_event e;
int res;

while (true)
{
void * context = NULL; /* to pass to thread */
res = epoll_wait(transport->epoll, &e, 1, (int)*60 * 12 * 1000));
if (res == 1)
{
*context = e.data.ptr;
}
/* wrapper to execute the worker thread */
cmThreadPoolExecute(transport->threadPool, context);
}
}

**worker thread**

static void threadBodySocketTransport(void * context)
{
msgBuffer * message;

message = parseMSG(context);
switch (message->cmd)
{
case WRITE:
doWriteOp(message);
break;
case READ:
doReadOp(message);
break;
case CREATE:
doCreateOp(message);
break;
}
}

void doWriteOp(msgBuffer * message)
{
#ifdef MULTITHREAD
/* wrapper to execute the worker thread */
cmThreadPoolExecute(threadPoolWrite, (void *)message);
#else
/* write to file */
threadBodyWrite(message);
#endif
}


**operation thread**

static void threadBodyWrite(void * context)
{
msgBuffer * message = (msgBuffer *)context;
int fd;

.
.(get the fd)
.
/* printf("w\n");*/
write(fd, message->write.data , message->write.len);
sendResponse(message->cmd, true);
}

**pthread create**
void threadStart(SYThread *taskIdPtr, void (*startpoint)(void), NQ_BOOL background)
{
pthread_attr_t attr;

pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(taskIdPtr, &attr, (void * (*)(void *))startpoint, NULL)
pthread_attr_destroy(&attr);
}

Maybe i need to use different thread attribute??

Please HELP.

Thanks.

Any hint?

Packet sequence:
(*)ack time - request time = ~50 micros
request
response(builtin ack)
request
request
ack
respons

(**)ack time - request time = ~50 micros
request
ack
response
request
request
ack
respons

Last edited by Ec5; 11-21-2016 at 01:59 AM. Reason: adding code
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Networking - Performance Based Routing WelshCJ Linux - Networking 0 07-02-2015 02:44 PM
The Largest Drawback for Linux nankura Linux - Games 31 03-09-2012 02:15 PM
LXer: High Performance Linux Networking Scalability LXer Syndicated Linux News 0 01-15-2008 09:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration