
网络
pud_zha
这个作者很懒,什么都没留下…
展开
-
详谈高性能TCP服务器的开发
转自:http://www.cnitblog.com/beifangying/archive/2008/07/24/47096.aspx对于开发一款高性能服务器程序,广大服务器开发人员在一直为之奋斗和努力.其中一个影响服务器的重要瓶颈就是服务器的网络处理模块.如果一款服务器程序不能及时的处理用户的数据.则服务器的上层业务逻辑再高效也是徒劳.所以一个服务器程序的网络处理能力直接影响到整个服务器的转载 2013-05-16 15:44:38 · 1342 阅读 · 0 评论 -
网络小结6
使用私有堆的原因1、避免和Default Heap的new 、delete操作符同步,提高性能2、分配的内存大小是固定的,减少内存空洞http://highscalability.com/blog/2013/5/13/the-secret-to-10-million-concurrent-connections-the-kernel-i.htmlhttp://www.k原创 2013-05-16 11:19:34 · 679 阅读 · 0 评论 -
socket error 10053,10054究竟是怎么引起的
贴2段能稳定重现10053的代码,下面是客户端:[cpp] view plaincopyWORD VersionRequested; WSADATA WsaData; VersionRequested = MAKEWORD(2, 2); if (WSAStartup(VersionRequested,转载 2013-05-15 18:18:40 · 1649 阅读 · 1 评论 -
编写IOCP时的几个注意事项(转自mirosoft)
TIP 1: Use Winsock2 IOCP-capable functions, such as WSASend and WSARecv, over Win32 file I/O functions, such as WriteFile and ReadFile. 提示1:尽量使用WSASend和WSARecv进行数据收发Socket handles from Micro转载 2013-05-09 14:37:59 · 1047 阅读 · 0 评论 -
使用IOCP需要注意的一些问题~~(不断补充)
转自:http://www.cppblog.com/johndragon/archive/2008/09/16/21845.html1- 不要为每个小数据包发送一个IOCP请求,这样很容易耗尽IOCP的内部队列.....从而产生10055错误.2- 不要试图在发送出IOCP请求之后,收到完成通知之前修改请求中使用的数据缓冲的内容,因为在这段时间,系统可能会来读取这些缓冲.转载 2013-05-03 17:49:38 · 1027 阅读 · 0 评论 -
IOCP不可忽视的细节
转自:http://mowen99.iteye.com/blog/1233932IOCP构架之所以公认高效,核心就在于异步IO。在网上纷纷为之膜拜之余,很少看到对稳定性或性能优化的观点。仔细想想,任何技术都有有利的一面,自然也有有弊的一面,这才符合辩证法思想。 我把自己在编写IOCP构架时重点处理的几个地方交代一下,如果你想认真写好一个稳定的IOCP服务端,建议重新规划以下几个细节。转载 2013-05-03 17:22:36 · 836 阅读 · 0 评论 -
[win32] Winsock 中应使用 DisconnectEx 关闭连接
在 maillist 上看到一则讯息,使用 closesocket() 只是让 OS 回收你的 socket,其实并没有给对方(peer)发送 FIN。因此对方(peer)在下次 recv() 的时候,会收到 "reset by peer" 的错误。而要主动给对方(peer)发送 FIN,要使用 DisconnectEx() 函数。而 MSDN 告知,DisconnectEx() 函数转载 2013-04-28 15:35:49 · 1752 阅读 · 0 评论 -
IOCP编程注意事项
1、每个连接同时最好只有一个待决的WSARecv。IOCP不保证多个待决WSARecv情况下先投递的WSARecv就一定会先得到完成通知。因此,多个待决WSARecv可能导致数据乱序,无谓增加代码复杂性。 2、投递0长度缓冲区的WSARecv可以不占用非分页内存,避免WSAENOBUFS错误。 3、每个连接同时最好只有一个待决的WSASend。发送数转载 2013-04-28 15:03:42 · 766 阅读 · 0 评论 -
winsock的部分总结
1.连接,要适用AcceptEx + WSAAsyncEvent来提供适量的连接数 connect上,boost::asio使用的是select()实现的reactor方法。2.必须使用memory pool/cache3.收发数据适用gatter-scatter模式:收集到一定量的buffer后再send,一次尽量多读取数据,然后传递给业务层。4.要明白IOCP适合高并发,大量原创 2013-03-21 19:42:35 · 930 阅读 · 0 评论 -
IOCP连接关闭
及时监测连接被动关闭 除非有特别要求,否则你应该总是对每个连接保持一个挂起的接收pending io(使用WSARecv投递)。如果用户主动关闭连接,你的GetQueuedCompletionStatus调用将返回成功,但接收到的数据长度为0,你能根据这点检测连接是否已被对方关闭。如果连接被重置或者io被取消(如果你调用了CancelIo的话),GetQueuedC转载 2013-01-21 15:26:44 · 4382 阅读 · 0 评论 -
libuv服务端
服务端:uv_tcp_init(uv_loop_t*loop, uv_tcp_t* handle):将各个变量初始化,并将handle插入双链表中。 uv_tcp_t:该类型包含socket成员变量。 uv_tcp_accept_t:内部使用类型,包含SOCKET accept_socket,缓冲区和event_handle, wait_handle调用uv_liste原创 2013-01-14 15:35:16 · 1103 阅读 · 0 评论 -
libuv之用CRITICAL_SECTION实现读写锁
typedef union { /* srwlock_ has type SRWLOCK, but not all toolchains define this type in */ /* windows.h. */ SRWLOCK srwlock_; struct { uv_mutex_t read_mutex_; uv_mutex_t write_m原创 2013-01-06 18:25:10 · 1645 阅读 · 0 评论 -
libuv之基础
TCP客户端连接步骤:① .连接方法Uv_loop_t *loop = uv_default_loop(); uv_tcp_t *client = malloc…;uv_connect_t* connect_req = malloc…; uv_tcp_init(loop, client) uv_tcp_connect(connect_req, client,原创 2013-01-06 16:13:18 · 13278 阅读 · 2 评论 -
65000个有效连接的IOCP封装类
关于这个类的几点总结:1.发送数据最大限制在MTU之类2.使用PreAllocate,分配内存时,同时为每片内存附加一个小结构体,指明该内存是否被使用,在析构时,只是设定为未使用,以使内存复用3.在Server端启动之前,先准备内存,并使用AcceptEx,缓冲大小设为04.将数据的接收和处理分开在不同的线程处理5.DWORD WINAPI WorkerThreadDumm原创 2012-12-26 17:55:04 · 887 阅读 · 0 评论 -
IOCP一些学习
ON_EN_CHANGE(IDC_CONTENT, &CClientDlg::OnEnChangeContent)1.数据的解析属于业务层的逻辑,不要放到网络层来2.CRITICAL_SECTION / MUTEXT 封装时注意把拷贝构造函数和复制构造函数私有化private:CCriSec(const CCriSec& cs);CCriSec operator = (cons原创 2012-12-25 14:45:47 · 753 阅读 · 0 评论 -
为什么要自己给SOCKET绑定一个值
The uniqueness of socketA normal SOCKET number itself is unique. But the OS assigns the socket number arbitrarily, the latest closed socket number could be re-assigned to a new socket connected ri转载 2012-12-25 10:23:13 · 1036 阅读 · 0 评论 -
使用WSASend改善网络程序的性能
socket本身有一个send函数,这个函数的只能一次发送一个缓冲区,这对于在发送大量数据的时候或者数据包很多的时候就可能导致可能导致系统的低性能,主要原因在于调用太多次的send函数,导致从用户态到核心态的不断切换,而耗费了当前的CPU时钟周期。那么解决办法就是减少调用send的次数,一种办法就是使用一个大一点的BUFFER,在发送数据的时候将多个数据包的内容COPY到这个BUFFER中转载 2012-11-23 22:33:51 · 662 阅读 · 0 评论 -
send/recv的超时模拟
Server如果只是不接受,send依旧成功如果退出不做任何处理,send返回失败只有将Server挂起,send才返回time-out因此,必须自己设计协议来保证两端的完整通信原创 2012-11-23 15:53:47 · 539 阅读 · 0 评论 -
clsoesocket, shutdown
closesocket shutdown:1.closesocket:关闭资源,shutdown关闭连接(reuse socket问题?)2.shutdown对udp没影响3.SO_LINGER:如果数据在关闭前发送就是graceful close,如果直接关闭就是hard clsoe这个选项应该只在block下使用,在non-block下,调用closesocket()会原创 2012-11-23 10:56:13 · 720 阅读 · 0 评论 -
网络小计5
1.host 和 ip 转换char *ip = "www.baidu.com";int value = inet_addr(ip);if( value == INADDR_NONE ){hostent *phost = gethostbyname(ip);int i = 0;while( phost->h_addr_list[i] != NULL ) //注意:不原创 2012-11-22 15:56:32 · 816 阅读 · 0 评论 -
高并发服务器适时投递accept的方法
On Windows 2000 and later versions, Winsock provides a mechanism for determining if an application is running behind in posting adequateAcceptEx calls. When creating the listening socket, associate转载 2012-11-20 17:27:32 · 1096 阅读 · 0 评论 -
关于高并发服务器的listen函数参数设置
int listen(int fd, int backlog);socket系统调用listen只被tcp 服务器使用,他做两件事:1. 将未链接的套接口转换为被动套接口,指示内核接受向此套接口的连接请求,调用此系统调用后tcp 状态机有close转换到listen.2.第二个参数制定了内核为此套接口排队的最大连接个数。关于第二个参数,对于给定的监听套接口,内核要维护两个队转载 2012-11-20 15:55:32 · 3153 阅读 · 0 评论 -
网络小记4
1.Overlapped IO模型:在处理线程中①Wait ForMultipleEventObjects②调用GetOverlappedResult对①关联的SOCKET进行结果验证If the WSAGetOverlappedResult function succeeds, the return value isTRUE. This means that your ove原创 2012-11-18 21:45:59 · 498 阅读 · 0 评论 -
send 和 WSASend性能比较
socket本身有一个send函数,这个函数的只能一次发送一个缓冲区,这对于在发送大量数据的时候或者数据包很多的时候就可能导致可能导致系统的低性能,主要原因在于调用太多次的send函数,导致从用户态到核心态的不断切换,而耗费了当前的CPU时钟周期。那么解决办法就是减少调用send的次数,一种办法就是使用一个大一点的BUFFER,在发送数据的时候将多个数据包的内容COPY到这个BUFFER中转载 2012-09-30 01:02:21 · 11960 阅读 · 0 评论 -
sockaddr_in , sockaddr , in_addr区别
sockaddr_in , sockaddr , in_addr区别struct sockaddr { unsigned short sa_family; char sa_data[14]; }; 上面是通用的socket地址,具体到Interne转载 2012-09-29 23:21:41 · 739 阅读 · 0 评论 -
网络小记3
1.The advantage of using select is the capability to multiplex connections and I/O on many sockets from a single thread2. we need to make one subtle distinction. The WSAAsyncSelect and WSAEventSel原创 2012-09-29 15:05:30 · 430 阅读 · 0 评论 -
Get Closer to the Wire with High-Performance Sockets in .NET
Daryn KielyParts of this article are based on a prerelease version of the .NET Framework 2.0. Those sections are subject to change.This article discusses:Basic socket program转载 2012-09-29 14:16:50 · 2021 阅读 · 0 评论 -
I/O Multiplexing & Scalable Socket Servers
(引自:http://www.drdobbs.com http://www.artima.com/)The Session Initiation Protocol (SIP) is a signaling protocol for Internet conferencing, telephony, presence, event notification, and instant mess转载 2012-09-29 13:41:23 · 1841 阅读 · 0 评论 -
WSA_FLAG_OVERLAPPED Is Needed for Non-Blocking Sockets
SUMMARYThe Winsock 2 socket flag WSA_FLAG_OVERLAPPED needs to be set if the socket will be used in non-blocking mode when running on Windows NT 4.0. Failure to set this flag can result in subsequent转载 2012-09-29 10:34:33 · 1186 阅读 · 0 评论 -
Socket overlapped I/O versus blocking/nonblocking mode
Article ID: 181611 - View products that this article applies to.This article was previously published under Q181611Expand all |Collapse allOn This PageSUMMARYMORE INFORMATION转载 2012-09-29 10:27:26 · 1939 阅读 · 0 评论 -
网络小计2
1.对于要处理众多小连接的服务器,需要投递更多的AcceptEx检查系统是否有足够AcceptEx的一个方法是:将WSAEventSelect关联到FD_ACCEPT,如果有连接到来而没有足够的AcceptEx时,注册事件会被触发AcceptEx的一个好处是:接收连接同时会接受数据,For servers whose clients send an initial reques原创 2012-09-28 11:07:51 · 731 阅读 · 0 评论 -
SOCKET各种模型下并发数量
SOCKET各种模型下并发数量 今天在公司认真的看了一下SOCKET的编程,对其中一些编程模型的并发数量原来一直是半清不明,正好趁着做当前项目的机会把他理清,目前在SOCKET上的编程模型主要有以下几种(WIN为主,LINUX和UNIX用得较少):1、普通的阻塞和非阻塞编程。利用线程池技术和内存池,SOCKET池技术,基本可以处理一千五百个左右的SOCKET连接,转载 2012-09-28 00:40:32 · 748 阅读 · 0 评论 -
网络小计1
1.使用同步SOCKET就用select模型,并且最好带一个超时2.Assuming 0 is an invalid socket handle value. Uncontrollably lame.3the proper closure of a connected stream socket involves:call shutdown() with the how e原创 2012-09-27 17:41:42 · 467 阅读 · 0 评论 -
High performance IOCP
IO Completion Ports provide a specialised notification mechanism for completed asynchronous I/O. Completed I/O is queued at an object called a completion port which then calls a programmer-supplied ca原创 2012-09-05 18:51:22 · 755 阅读 · 0 评论 -
Designing High-Performance Windows Client/Server Socket Classes
Designing High-Performance Windows Client/Server Socket Classes Author: Sahlan Diver, ContractorDate: Jan 2009Revised: April 2009Revised May 2nd 2009 after further simplifications to the cod转载 2012-09-05 16:14:48 · 1813 阅读 · 0 评论 -
WinSock Tips
1.使用同步SOCKET就用select模型,并且最好带一个超时2.Assuming 0 is an invalid socket handle value. Uncontrollably lame.3the proper closure of a connected stream socket involves:call shutdown() with the how equ原创 2012-09-05 15:31:29 · 642 阅读 · 0 评论 -
Slow performance occurs when you copy data to a TCP server by using a Windows Sockets API program
Slow performance occurs when you copy data to a TCP server by using a Windows Sockets API programArticle ID: 823764 - View products that this article applies to.System TipThis article applie转载 2012-08-31 15:34:05 · 1104 阅读 · 0 评论 -
Which I/O Strategy Should I Use?
by Warren YoungThere are several different conventions for communicating with Winsock, and each method has distinct advantages. The question of the hour is, what are these advantages, and how does转载 2012-08-31 15:02:44 · 1666 阅读 · 0 评论 -
TCP RST: Calling close() on a socket with data in the receive queue
TCP RST: Calling close() on a socket with data in the receive queue Consider two peers, A and B, communicating via TCP. If B closes a socket and there is any data in B’s receive queue, B sends a转载 2012-08-31 10:47:03 · 940 阅读 · 0 评论 -
Socket编程中的强制关闭与优雅关闭及相关socket选项
以下描述主要是针对windows平台下的TCP socket而言。首先需要区分一下关闭socket和关闭TCP连接的区别,关闭TCP连接是指TCP协议层的东西,就是两个TCP端之间交换了一些协议包(FIN,RST等),具体的交换过程可以看TCP协议,这里不详细描述了。而关闭socket是指关闭用户应用程序中的socket句柄,释放相关资源。但是当用户关闭socket句柄时会隐含的触发TCP转载 2012-08-31 10:40:10 · 1263 阅读 · 0 评论