简体   繁体   中英

How Windows routing works on application level?

Imagine I have Windows TCP socket. And the application connects this socket once on startup. And then sends/receives TCP traffic for long time .

Windows has ability to route IP traffic. Imagine you have multiple network adaptors and you have to set static routing for your application that the traffic goes to a particular NIC.

The question is - will Windows waste CPU cycles to route TCP socket connection only or will it route every IP packet?

I am counting microseconds and I need to know precisely - will be there CPU overhead on sending / receiving the traffic or connection only ?

I assume by "routing" you mean the process of looking at the local routing table to decide where an outgoing packet should be sent. This is decided first by which router to use, and second which interface to use to get to that router.

If you have established a static route, "routing" must still occur for the system to see that route. This consists of a table lookup which takes just a few dozen machine instructions. It is absolutely negligible compared to the cost of copying the packet around.

Keep in mind that binding a socket to a network interface is not the same as entering static rules into the routing table, and that a network interface is not the same as a Network Interface Controller (NIC). This is important when considering overhead, because the effect of binding or routing to a particular network interface, may be that the packet gets copied extra times which will create substantial overhead.

It is possible to contrive a scenario in which a packet is transmitted on the LAN, re-read by the same computer that transmitted it, then transmitted again through a different NIC to the correct router. Most often, the best performance will be had by binding to INADDR_ANY (address 0.0.0.0 ) and letting the routing tables handle the optimization for you.

Binding to a particular network interface should only be done if you need to ensure that a particular IP address is used for sending and receiving. Static routing to a particular NIC seems unlikely to produce useful results unless the local routing is already broken in some way. Otherwise, interfering with the normal routing process just risks adding to the overhead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM