1- using NetworkLibrary . TCP ;
1+ using NetworkLibrary ;
2+ using NetworkLibrary . Components . Statistics ;
3+ using NetworkLibrary . TCP ;
24using NetworkLibrary . TCP . ByteMessage ;
35using NetworkLibrary . Utils ;
46using System ;
@@ -27,6 +29,7 @@ static void Main(string[] args)
2729
2830 private static void TcpTest ( )
2931 {
32+ BufferPool . ForceGCOnCleanup = false ;
3033 // dont change.
3134 int NumFinishedClients = 0 ;
3235 //CoreAssemblyConfig.UseUnmanaged=true;
@@ -41,13 +44,13 @@ private static void TcpTest()
4144 var response = new byte [ 32 ] ;
4245
4346
44- ByteMessageTcpServer server = new ByteMessageTcpServer ( 2008 , clientAmount * 2 ) ;
47+ ByteMessageTcpServer server = new ByteMessageTcpServer ( 2008 ) ;
4548 List < ByteMessageTcpClient > clients = new List < ByteMessageTcpClient > ( ) ;
4649
4750 Stopwatch sw2 = new Stopwatch ( ) ;
4851 AutoResetEvent testCompletionEvent = new AutoResetEvent ( false ) ;
4952
50- server . MaxIndexedMemoryPerClient = 1280000000 ;
53+ server . MaxIndexedMemoryPerClient = 12800000 ;
5154 server . ClientSendBufsize = 128000 ;
5255 server . ClientReceiveBufsize = 128000 ;
5356 server . DropOnBackPressure = false ;
@@ -60,9 +63,8 @@ private static void TcpTest()
6063 for ( int i = 0 ; i < clientAmount ; i ++ )
6164 {
6265 var client = new ByteMessageTcpClient ( ) ;
63- client . BufferManager = server . BufferManager ;
6466 client . MaxIndexedMemory = server . MaxIndexedMemoryPerClient ;
65-
67+ client . GatherConfig = ScatterGatherConfig . UseQueue ;
6668 client . DropOnCongestion = false ;
6769 client . OnBytesReceived += ( byte [ ] arg2 , int offset , int count ) => OnClientReceivedMessage ( client , arg2 , offset , count ) ;
6870
@@ -167,6 +169,7 @@ void OnServerReceviedMessage(in Guid id, byte[] arg2, int offset, int count)
167169
168170 private static void TcpTest2 ( )
169171 {
172+
170173 // dont change.
171174 int NumFinishedClients = 0 ;
172175 MiniLogger . AllLog += ( string log ) => Console . WriteLine ( log ) ;
@@ -180,25 +183,26 @@ private static void TcpTest2()
180183 var response = new byte [ 32 ] ;
181184
182185 bool done = false ;
183- int port = 20011 ;
184- ByteMessageTcpServer server = new ByteMessageTcpServer ( port , clientAmount * 3 ) ;
186+ int port = 20007 ;
187+ ByteMessageTcpServer server = new ByteMessageTcpServer ( port ) ;
185188 List < ByteMessageTcpClient > clients = new List < ByteMessageTcpClient > ( ) ;
186189
187190 Stopwatch sw2 = new Stopwatch ( ) ;
188191 AutoResetEvent testCompletionEvent = new AutoResetEvent ( false ) ;
189192
190- server . MaxIndexedMemoryPerClient = 128000 ;
193+ server . MaxIndexedMemoryPerClient = 128000000 ;
191194 server . ClientSendBufsize = 128000 ;
192195 server . ClientReceiveBufsize = 128000 ;
193196 server . DropOnBackPressure = false ;
194197 server . OnBytesReceived += OnServerReceviedMessage ;
195198 server . StartServer ( ) ;
199+ server . GatherConfig = ScatterGatherConfig . UseQueue ;
196200
197201 Task [ ] toWait = new Task [ clientAmount ] ;
198202 for ( int i = 0 ; i < clientAmount ; i ++ )
199203 {
200204 var client = new ByteMessageTcpClient ( ) ;
201- client . BufferManager = server . BufferManager ;
205+ client . GatherConfig = ScatterGatherConfig . UseQueue ;
202206 client . MaxIndexedMemory = server . MaxIndexedMemoryPerClient ;
203207
204208 client . DropOnCongestion = false ;
@@ -221,21 +225,13 @@ private static void TcpTest2()
221225 for ( int i = 0 ; i < numMsg ; i ++ )
222226 {
223227 client . SendAsync ( message ) ;
224-
225228 }
226229
227- } ) ;
228230
229- Task . Run ( async ( ) =>
230- {
231- while ( ! done )
232- {
233- await Task . Delay ( 2000 ) ;
234- //ShowStatus();
235- }
236-
237231 } ) ;
238232
233+
234+
239235 // -------- Messages are sent by clients ------
240236
241237 Console . WriteLine ( "All messages are dispatched in :" + sw2 . ElapsedMilliseconds +
@@ -271,8 +267,12 @@ void ShowStatus()
271267 Console . WriteLine ( " Request-Response Per second " + ( totMsgClient / elapsedSeconds ) . ToString ( "N1" ) ) ;
272268 Console . WriteLine ( "Data transmissıon rate Inbound " + ( message . Length * messagePerSecond / 1000000 ) . ToString ( "N1" ) + " Megabytes/s" ) ;
273269 Console . WriteLine ( "Data transmissıon rate Outbound " + ( response . Length * messagePerSecond / 1000000 ) . ToString ( "N1" ) + " Megabytes/s" ) ;
270+ server . GetStatistics ( out SessionStats general , out var _ ) ;
271+ Console . WriteLine ( general . ToString ( ) ) ;
274272 }
275273
274+ //--------------- Msg Handlers ---------------------
275+
276276 void OnClientReceivedMessage ( ByteMessageTcpClient client , byte [ ] arg2 , int offset , int count )
277277 {
278278 Interlocked . Increment ( ref totMsgClient ) ;
0 commit comments