[sr-dev] Big TCP message

Klaus Darilion klaus.mailinglists at pernau.at
Thu Jan 3 16:15:10 CET 2013


Ups.

On 03.01.2013 15:11, Klaus Darilion wrote:
> How much traffic do you want to send?
>
> When does the problem happen? At which message size does it happen?
>
> I just wonder that the normal options which works for us do not work for
> you and t
and the problem is code related.

1. Check if Kamailio really uses the buffer size you have configured 
(via sercmd config framework):
# kamctl sercmd cfg.get tcp rd_buf_size

2. Test on which message size the problems start. Attached is a perl 
script which allows you to generate OPTIONS messages with a specified 
message size, e.g:

# ./send-tcp-message.pl 127.0.0.1:5060 2048


regards
Klaus

>
> regards
> Klaus
>
> On 03.01.2013 14:21, Amit Elbaz wrote:
>> I increased tcp_rd_buf_size, but it did not help.
>> I don't think this is the problem.
>>
>> In tcp_read.c:
>> int tcp_read(struct tcp_connection *c, int* flags)
>> {
>> int bytes_free, bytes_read;
>> struct tcp_req *r;
>> int fd;
>>
>> r=&c->req;
>> fd=c->fd;
>> bytes_free=r->b_size- (int)(r->pos - r->buf);
>> if (unlikely(bytes_free==0)){
>> LOG(L_ERR, "ERROR: tcp_read: buffer overrun, dropping\n");
>> r->error=TCP_REQ_OVERRUN;
>> return -1;
>> }
>>
>> how to i increase r->b_size ?
>>
>> Thanks for you help, Amit.
>>
>> On Wed, Jan 2, 2013 at 6:51 PM, Klaus Darilion
>> <klaus.mailinglists at pernau.at <mailto:klaus.mailinglists at pernau.at>>
>> wrote:
>>
>>     Hi!
>>
>>     -b is the receive buffer of the socket in the OS (for UDP tweaking,
>>     I do not know if this is relevant for TCP), so not related to this
>>     problem as this problem happens inside Kamailio.
>>
>>     Actually 15K is rather small, really strange that you get errors.
>>     So, I did some tests:
>>
>>     1. tcp_rd_buf_size must be increased. The documentation is bad as it
>>     meantions "TCP datagram" but actually means the maximum size of SIP
>>     (or HTTP) message that can be received.
>>
>>     2. tcp_rd_buf_size is internally limited to 16MBytes. If you need
>>     more, you have to change the code in:
>>     tcp_options.c:  { "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512,
>>     16777216,  0,         0,
>>
>>     3. If you use real large message you may need to increase the
>>     private memory, and if you forward it with tm module, also the
>>     shared memory.
>>
>>     regards
>>     Klaus
>>
>>
>>     Am 02.01.2013 13:59, schrieb Amit Elbaz:
>>>     this still does not solve the problem.
>>>     I've also tried running Kamailio with *-b 32768* option.
>>>
>>>     here are the logs:
>>>
>>>     Jan  2 14:54:24 debdev kamailio[2580 <tel:%5B2580>]: ERROR: <core>
>>>     [tcp_read.c:344]: ERROR: tcp_read: buffer overrun, dropping
>>>     Jan  2 14:54:24 debdev kamailio[2580 <tel:%5B2580>]: ERROR: <core>
>>>     [tcp_read.c:1127]: ERROR: tcp_read_req: error reading
>>>
>>>     Thanks for your help.
>>>
>>>     On Wed, Jan 2, 2013 <tel:2013> at 1:17 PM, Andrew Pogrebennyk
>>>     <apogrebennyk at sipwise.com <mailto:apogrebennyk at sipwise.com>> wrote:
>>>
>>>         Hi,
>>>         you may try changing the tcp_rd_buf_size and tcp_conn_wq_max:
>>>
>>> http://www.kamailio.org/wiki/cookbooks/3.3.x/core#tcp_conn_wq_max
>>>
>>>         And since this in development mailing list I'd like to point
>>>         at what
>>>         seem an iaccuracy in documentation: several options refer to
>>>         the core
>>>         parameter called tcp_write_buf, which isn't described in the
>>>         cookbook:
>>>
>>>         tcp_conn_wq_max
>>>         Maximum bytes queued for write allowed per connection.
>>>         Attempting to
>>>         queue more bytes would result in an error and in the
>>>         connection being
>>>         closed (too slow). If *tcp_write_buf* is not enabled, it has
>>>         no effect.
>>>
>>>         I hope Daniel or someone who knows reads this..
>>>
>>>         BR,
>>>         Andrew
>>>
>>>         On 01/02/2013 10:38 AM, Amit Elbaz wrote:
>>>         > Hi,
>>>         >
>>>         > While sending a big TCP SIP message (15K+), I get "tcp_read:
>>>         buffer
>>>         > overrun, dropping" message.
>>>         > this happens after a few fragments have been sent, and then
>>>         i get this
>>>         > message and the connection resets.
>>>         > is it possible to set the max-buffer size through
>>>         configuration? if so,
>>>         > where?
>>>         >
>>>         > Thanks, Amit.
>>>         >
>>>         >
>>>         > _______________________________________________
>>>         > sr-dev mailing list
>>>         > sr-dev at lists.sip-router.org
>>> <mailto:sr-dev at lists.sip-router.org>
>>>         > http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>>>         >
>>>
>>>
>>>         _______________________________________________
>>>         sr-dev mailing list
>>>         sr-dev at lists.sip-router.org <mailto:sr-dev at lists.sip-router.org>
>>>         http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>>>
>>>
>>>
>>>
>>>     _______________________________________________
>>>     sr-dev mailing list
>>>     sr-dev at lists.sip-router.org  <mailto:sr-dev at lists.sip-router.org>
>>>     http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>>
>>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
-------------- next part --------------
#!/usr/bin/perl -w
#
# syntax: send-tcp-message.pl <host:port> <size> [<id>]

if ( @ARGV < 2 ) {
	print "ERROR, need at least 2 parameters. Syntax is:\n";
	print "  send-tcp-message.pl <host:port> <size> [<id>]\n";
	print "    host:port: where to send the request\n";
	print "    size: total size of the request, including headers and body\n";
	print "    id: optional, parameter used in from-tag, call-id and Via-branch\n";
	print "  exit the programm with CTRL-C\n";
	print "\n";
	print "Examples:\n";
	print "  send-tcp-message.pl 127.0.0.1:5060 1200\n";
	print "  send-tcp-message.pl 127.0.0.1:5060 100k   (100*1000)\n";
	print "  send-tcp-message.pl 127.0.0.1:5060 10m    (10*1000*1000)\n";
	print "  send-tcp-message.pl 127.0.0.1:5060 100K   (100*1024)\n";
	print "  send-tcp-message.pl 127.0.0.1:5060 10M    (10*1024*1024)\n";
	exit(1);
}

# URI to be used in the SIP message (RURI, From, To)
my $uri = "sip:test\@example.com";

# connect to destination
use IO::Socket;
my $server = $ARGV[0];
$remote = IO::Socket::INET->new(
	Proto    => "tcp",
	PeerAddr => "$server",
);
if ( !$remote) { 
	print "ERROR: Cannot connect to $server\n";
	exit(1);
}

# create random id for from-tag, call-id and Via-branch
my $id;
if(!defined $ARGV[2]) {
	$id = int(rand(10000000000))+1;
} else {
	$id = $ARGV[2];
}

# convert message size
my $size = $ARGV[1];
if ( substr($ARGV[1],-1,1) eq "k") {
	$size = substr($ARGV[1],0,length($ARGV[1])-1) * 1000;
}
if ( substr($ARGV[1],-1,1) eq "m") {
	$size = substr($ARGV[1],0,length($ARGV[1])-1) * 1000*1000;
}
if ( substr($ARGV[1],-1,1) eq "K") {
	$size = substr($ARGV[1],0,length($ARGV[1])-1) * 1024;
}
if ( substr($ARGV[1],-1,1) eq "M") {
	$size = substr($ARGV[1],0,length($ARGV[1])-1) * 1024*1024;
}

$headers = <<END;
OPTIONS $uri SIP/2.0\r
Via: SIP/2.0/TCP 127.0.0.1:5061;branch=z9hG4bK-$id;rport\r
From: <$uri>;tag=$id\r
To: <$uri>\r
Call-ID: $id\r
CSeq: 1 OPTIONS\r
Contact: sip:foobar\@127.0.0.1\r
Content-Type: text/plain\r
Content-Length: 0000000000\r
Expires: 30\r
Event: presence\r
Accept: application/pidf+xml, application/xpidf+xml\r
Supported: eventlist\r
Accept: application/rlmi+xml\r
Accept: multipart/related\r
\r
END

my $headerslen = length($headers);
my $bodylen = $size - $headerslen;
if ($bodylen < 0) {
	print "ERROR: The size of the message headers ($headerslen) is already bigger then the specified message size ($size)!\n";
	exit(1);
}
my $body = 'a' x $bodylen;

my $bodylenstring = sprintf("%010d", $bodylen);
$headers=~ s/0000000000/\Q$bodylenstring/;

print "Sending a SIP message with $size bytes to $server\n";
print "Message headers are:\n";
print $headers;

print $remote $headers;
print $remote $body;

print "Finished sending a SIP message with $size bytes to $server\n";
print "Waiting for a response. Press CTRL-C to exit.\n\n";

while ( <$remote> ) { 
	print 
}


More information about the sr-dev mailing list