Are there any performance issues with CSocket :: Send?

UPDATE June 14, 2011

Quick update ... Most of the respondents focused on the ingenious method of processing the queue of messages to be recorded, but despite the lack of optimization there, of course, this is not the root of the problem. We switched Income to a short sleep (yes, Yield really led to a 100% CPU as soon as the system went blank), however, the system still cannot keep up with the registration, even when it does not come close to this dream. From what I see, Send is simply not very efficient. One of the respondents commented that we should block Send () together with one send, and this would seem like the most suitable solution for a larger main problem and that I noted this as an answer to the original question. Of course, I agree that the queue model is very wrong, so thanks for the feedback on this, and I voted for all the answers,who contributed to the discussion.

However, this exercise allowed us to analyze why we use external logging on a socket, as we do, and although this may make sense earlier when the log server processed a lot of log records. he doesnโ€™t do this anymore, and so we chose to remove the entire module and go to the approach with direct access to the file using any previously existing logging system, this should completely fix the problem, as well as eliminate unnecessary complexity in the system.

Thanks again for the feedback.

ORIGINAL QUESTION

In our system, we have two components important for this task: one of them is developed in Visual C ++, and the other is Java (do not ask, historical reasons).

The C ++ component is the main service and generates log entries. These log entries are sent through CSocket :: Send to the Java Logging Service.

. ++, .

Java Logging Server #, , - ++, .

++ :

void MyLogger::Log(const CString& buffer)
{
    struct _timeb timebuffer;
    _ftime64_s( &timebuffer );

    CString message;
    message.Format("%d%03d,%04d,%s\r\n", (int)timebuffer.time, (int)timebuffer.millitm, GetCurrentThreadId(), (LPCTSTR)buffer);

    CString* queuedMessage = new CString(message);
    sendMessageQueue.push(queuedMessage);
}

, , ,:

void MyLogger::ProcessQueue()
{
    CString* queuedMessage = NULL;
    while(!sendMessageQueue.try_pop(queuedMessage))
    {
        if (!running)
        {
            break;
        }
        Concurrency::Context::Yield();
    }

    if (queuedMessage == NULL)
    {
        return;
    }
    else
    {
        socket.Send((LPCTSTR)*queuedMessage, queuedMessage->GetLength());
        delete queuedMessage;
    }
}

, ProcessQueue , :

while(parent->running)
{
    try
    {
        logger->ProcessQueue();
    }
    catch(...)
    {
    }
}

:

Concurrency::concurrent_queue<CString*> sendMessageQueue;

, , , , , , , .

CSocket:: Send, ? ? - ?

.

+3
4

-, . Send() . . , Send(), .

, , . PPL , , call. , .

+1

, - "". , - , , , , , . , . , , , . , , . socket.send.

, .

Rgds,

+3

:

  • , . , . Concurrency:: concurrent_queue, pop(). , Concurrency , , , CPU .
  • CString.. , ( ) : 1. . 2. , , , .
+1

, , ? , ? CPU ?

The only thing I see is that you are not protecting the message queue with any kind of lock, so the state of the container can become strange, causing all kinds of unexpected actions.

0
source

All Articles