{"id":26,"date":"2010-04-23T10:55:22","date_gmt":"2010-04-23T10:55:22","guid":{"rendered":"http:\/\/karlsblog.bigmight.com\/blog\/?p=26"},"modified":"2016-10-20T21:44:54","modified_gmt":"2016-10-20T21:44:54","slug":"poll-push-or-pull-which-is-best","status":"publish","type":"post","link":"https:\/\/karlsblog.bigmight.com\/blog\/2010\/04\/23\/poll-push-or-pull-which-is-best\/","title":{"rendered":"Poll, Push or Pull &#8211; Which is best&#8230;."},"content":{"rendered":"<h2>What do we mean by &#8220;Poll&#8221;, &#8220;Push&#8221; and &#8220;Pull&#8221; in terms of data communication<\/h2>\n<p>Communications systems either &#8220;Push&#8221; or &#8220;Pull&#8221; data, but in some cases, when you need to know if anything is waiting a &#8220;Poll&#8221; is performed, these techniques each have advantages and disadvantages discussed here.<\/p>\n<h2>Polling<\/h2>\n<p>Polling is asking whether data is available, or can be sent, for example the pop3 protocol used by main readers. It is very simple and has the advantage that the server being polled need not know anything about the polling client state. The polling client must make periodic requests to the server to determine if data is ready or can be sent.<\/p>\n<p>The disadvantages of &#8220;Polling&#8221; are that the polling client will not know exactly when it can send or receive data, hence to reduce latency the poll interval may need to be quite frequent increasing the server overhead, especially if it serves a number of clients.<\/p>\n<p>If the polling interval is set to <em>n<\/em>, and the data transfer time <em>m<\/em>, then the average delivery\/fetch latency is <em>n\/2 + m<\/em>. This can be a limit in many systems.<\/p>\n<p>Computer hardware has historically suffered from issues where some hardware did not use interrupts to indicate data reception, or, like in the PC the old interrupt controller having limited interrupts caused devices to share an interrupt. This in turn increased interrupt latency as the <a title=\"IBM PC Wiki\" href=\"http:\/\/en.wikipedia.org\/wiki\/IBM_Personal_Computer\">IBM PC<\/a> had to <strong>poll<\/strong> all the hardware devices sharing this interrupt to determine the interrupt source. Hence the evolution of the <a title=\"APIC Controller\" href=\"http:\/\/en.wikipedia.org\/wiki\/Advanced_Programmable_Interrupt_Controller\">APIC<\/a>.<\/p>\n<p>Polling is a solution only to used where servers need not know availability of clients, low latency is unimportant and the host being polled is able to handle the amount of polling requests.<\/p>\n<p>Examples of services using &#8220;Poll&#8221; are <a title=\"NTP Time Synchornisation\" href=\"http:\/\/www.ntp.org\/\">NTP<\/a>, <a title=\"Post Office Protocol V3\" href=\"http:\/\/www.ietf.org\/rfc\/rfc1939.txt\">POP3<\/a>,<\/p>\n<h2>Pushing<\/h2>\n<p>Pushing of data is highly efficient and is where a host pushes data to the receiving host. Many protocols use such schemes such as:-<\/p>\n<ul>\n<li><a title=\"open source printing system developed by Apple\" href=\"http:\/\/www.cups.org\/\">Cups <\/a>(Printed files are pushed to print server)<\/li>\n<li><a title=\"File Transfer Protocol\" href=\"http:\/\/www.faqs.org\/rfcs\/rfc959.html\">FTP<\/a> (oddly uses &#8220;Pull&#8221; as well) (files are ushed to remove server)<\/li>\n<li><a title=\"Unix Line Printer Daemon Protocol\" href=\"http:\/\/www.ietf.org\/rfc\/rfc1179.txt\">LPR<\/a> (Printed files are pushed to print server)<\/li>\n<li><a title=\"Secure File Transfer Protocol\" href=\"http:\/\/en.wikipedia.org\/wiki\/SSH_file_transfer_protocol\">SFTP<\/a> (Secure FTP using ssh wrapper)<\/li>\n<li><a title=\"Simple Network Messaging Protocol\" href=\"http:\/\/en.wikipedia.org\/wiki\/Simple_Network_Management_Protocol\">SNMP<\/a> (Simple Network Messaging Protocol)<\/li>\n<li><a title=\"Simple Mail Transfer Protocol\" href=\"http:\/\/en.wikipedia.org\/wiki\/Simple_Mail_Transfer_Protocol\">SMTP<\/a> (Internet email delivery &#8211; very old &#8211; very reliable)<\/li>\n<li>Hardware Interrupts<\/li>\n<\/ul>\n<p>&#8220;Pushing&#8221; is best used where data is ready for delivery and the client can accept data at any time.<\/p>\n<h3>Double Buffering<\/h3>\n<p>In some cases, such as writing large amounts of data to a &#8220;block&#8221; based piece of hardware, double buffering can be used to vastly reduce latency.<\/p>\n<p>Consider a network adapter, which has an output buffer, and interrupts when it has completed a transmit. The OS writes a packet of data to the buffer, then waits for the card to send the data. When the hardware has successfully send the data it interrupts the OS to inform that it is ready to receive more data, but the time taken for the OS to service the interrupt filling the transmit buffer may delay a successive network transmit, adding unwanted delay between packets.<\/p>\n<p>The solution is to utilise two transmit buffers in the hardware device, buffer a and b. Following successful transmission of buffer a, the network adapter will start to tranmit the data in buffer b (if ready) as well as interrupt the computer to instigate a data copy to buffer a. This ensures that the delay following the interrupt and the OS copy of data to buffer a does not add additional latency to the system. The OS software requires little change to cater for this type of system, but the throughput gains are massive. The overall latency of the system is not reduced, but the throughput is increased.<\/p>\n<h1>Pulling<\/h1>\n<p>Pulling of data is done when a client requires data, and is normally served by fast services. Most client user interfaces use &#8220;Pull&#8221; type services to achieve the fast response expected by a user. Examples of such services are:-<\/p>\n<ul>\n<li>FTP<\/li>\n<li><a title=\"Hypertext Transfer Protocol\" href=\"http:\/\/en.wikipedia.org\/wiki\/Hypertext_Transfer_Protocol\">HTTP<\/a> (driving the internet)<\/li>\n<\/ul>\n<p>The HTTP protocol is a best use case, where users pull content &#8220;On Demand&#8221; and has driven the last 20 years of Internet development.<\/p>\n<h2>Conclusion<\/h2>\n<p>Most data communications systems work best when &#8220;Pulling&#8221; or &#8220;Pushing&#8221; data, the use of a &#8220;Poll&#8221; type system should be avoided unless their is a clear business case.<\/p>\n<p>When designing systems it&#8217;s often simpler to implement a scheme which works &#8220;Sufficiently Well&#8221;, but if designed inappropriately\u00a0 requires more resources and power. It is often possible to implement systems that utilise very few resources by careful interface designs, and for <a title=\"wmbedded software development\" href=\"\/software_development.mhtml\">low power embedded devices<\/a> this is so important.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What do we mean by &#8220;Poll&#8221;, &#8220;Push&#8221; and &#8220;Pull&#8221; in terms of data communication Communications systems either &#8220;Push&#8221; or &#8220;Pull&#8221; data, but in some cases, when you need to know if anything is waiting a &#8220;Poll&#8221; is performed, these techniques each have advantages and disadvantages discussed here. Polling Polling is asking whether data is available, &hellip; <a href=\"https:\/\/karlsblog.bigmight.com\/blog\/2010\/04\/23\/poll-push-or-pull-which-is-best\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Poll, Push or Pull &#8211; Which is best&#8230;.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/posts\/26"}],"collection":[{"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":7,"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":54,"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/posts\/26\/revisions\/54"}],"wp:attachment":[{"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/karlsblog.bigmight.com\/blog\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}