Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences in Default Network Packet Size: SqlConnection vs. SQL Server defaults

I noticed yesterday that there is a noticeable difference between the default network packet size in .NET's SqlConnection class and the default in SQL Server itself.

For the SqlConnection class' PacketSize property, per this link:

The size (in bytes) of network packets. The default value is 8000.

In previous versions of that article, it mentions (all the way back to .NET 1.1) that the default was 8192 bytes. For SQL Server, however (per this link):

The default packet size is 4,096 bytes.

From that article it appears that that's been the default since at least SQL Server 2005. Does anyone know the reason for this difference between them?

UPDATE: To add more fun to this question, I've been talking to Thomas LaRock (who happens to be a SQL MVP), and he mentioned to me that in SQL Server 2000 the default network packet size was, in fact, 8192 bytes (like .NET 1.1!). It got changed in later versions, though, because of how much fragmentation it was causing, necessitating weekly reboots of the server.

So why did SQL Server reduce it by half, but .NET only reduced it by 192 bytes? Is there something forcing SQL Server to use only multiples of 2 for this?

like image 402
Corey Adler Avatar asked Mar 10 '15 14:03

Corey Adler


People also ask

What is network packet size in SQL Server?

The network packet size configuration option in SQL Server is used to set the package size (in bytes) to be used when communicating with SQL server. The size can be set on the server side as well as on some of the client side libraries. The default packet size set by Microsoft SQL Server is 4,096 bytes.

What is the size of a network packet?

The maximum size of a TCP packet is 64K (65535 bytes). Generally, the packet size gets restricted by the Maximum Transmission Unit (MTU) of network resources. MTU is the maximum size of the data transfer limit set by hardware in a network. The packet size should never exceed MTU.

What is packet size in connection string?

PacketSize may be a value in the range of 512 and 32767 bytes. An exception is generated if the value is outside this range.

What should be the connection string for SQL Server?

The following connection string will connect the database using windows authentication. Server=ServerName;Database=DatabaseName;Trusted_Connection=True; With help of the following C# code, this is how we can see the usage of a connection string in an application.


1 Answers

This has always been the case. Even in SQL 7.0 and SQL Server 2000, the default value was 4096 bytes.

The problem happens when you try to use a higher network memory than 8060 bytes as it will require SQL Server to allocate memory from a region of memory that uses a size of 384 MB.

Its very easy to modify the packet size from the client application side. In connection string, you just set the packet size=4096.

Its advisable not to fiddle with the default network size on a server running SQL Server, unless you are doing some heavy lifting using SSIS or your application is performing bulk copy operations, sending and receiving BLOB data.

Note that SybaseASE uses 512 bytes as default packet size, so SQL Server 6.5 might have that set as default (but I have no reference to cite if that was the case for SQL 6.5).

Refer to : Network Packet Size: to Fiddle With or Not to Fiddle With

like image 133
Kin Shah Avatar answered Oct 21 '22 10:10

Kin Shah