Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with polling?

I have heard a few developers recently say that they are simply polling stuff (databases, files, etc.) to determine when something has changed and then run a task, such as an import.

I'm really against this idea and feel that utilising available technology such as Remoting, WCF, etc. would be far better than polling.

However, I'd like to identify the reasons why other people prefer one approach over the other and more importantly, how can I convince others that polling is wrong in this day and age?

like image 704
HAdes Avatar asked Nov 26 '08 10:11

HAdes


People also ask

What are some problems with presidential elections?

Foreign policy and peace issues have always been important to presidential candidates. Issues Today Recent presidential elections have included a range of issues including: taxation, the national debt, education, civil rights, health care, and terrorism.

Are opinion polls biased?

If the people who do not answer have different opinions then there is bias in the results. In terms of election polls, studies suggest that bias effects are small, but each polling firm has its own techniques for adjusting weights to minimize selection bias.

How do polls affect presidential elections?

How do polls affect presidential elections? Polls help voters research information about each of the candidates. Polls tell voters the issues that candidates support. Polls identify the top candidates and the media interview those candidates.

Why are public opinion polls not always accurate quizlet?

Sample Answer: Public opinion polls are not always accurate because they can reflect bias depending upon the sampled polled, as when the sample is too narrow and is not accurately reflective of the population. Also, respondents are not always truthful; this can impact the accuracy of the poll.


2 Answers

Polling is not "wrong" as such.

A lot depends on how it is implemented and for what purpose. If you really care about immedatly notification of a change, it is very efficient. Your code sits in tight loop, constantly polling (asking) a resource whether it has changed / updated. This means you are notified as soon as you can be that something is different. But, your code is not doing anything else and there is overhead in terms of many many calls to the object in question.

If you are less concerned with immediate notification you can increase the interval between polls, and this can also work well, but picking the correct interval can be difficult. Too long and you might miss critical changes, too short and you are back to the problems of the first method.

Alternatives, such as interrupts or messages, etc. can provide a better compromise in these situations. You are notified of a change as soon as is practically possible, but this delay is not something you control, it depends on the component tself being timely about passing on changes in state.

What is "wrong" with polling?

  • It can be resource hogging.
  • It can be limiting (especially if you have many things you want to know about / poll).
  • It can be overkill.

But...

  • It is not inherently wrong.
  • It can be very effective.
  • It is very simple.
like image 78
xan Avatar answered Sep 18 '22 12:09

xan


Examples of things that use polling in this day and age:

  • Email clients poll for new messages (even with IMAP).
  • RSS readers poll for changes to feeds.
  • Search engines poll for changes to the pages they index.
  • StackOverflow users poll for new questions, by hitting 'refresh' ;-)
  • Bittorrent clients poll the tracker (and each other, I think, with DHT) for changes in the swarm.
  • Spinlocks on multi-core systems can be the most efficient synchronisation between cores, in cases where the delay is too short for there to be time to schedule another thread on this core, before the other core does whatever we're waiting for.

Sometimes there simply isn't any way to get asynchronous notifications: for example to replace RSS with a push system, the server would have to know about everyone who reads the feed and have a way of contacting them. This is a mailing list - precisely one of the things RSS was designed to avoid. Hence the fact that most of my examples are network apps, where this is most likely to be an issue.

Other times, polling is cheap enough to work even where there is async notification.

For a local file, notification of changes is likely to be the better option in principle. For example, you might (might) prevent the disk spinning down if you're forever poking it, although then again the OS might cache. And if you're polling every second on a file which only changes once an hour, you might be needlessly occupying 0.001% (or whatever) of your machine's processing power. This sounds tiny, but what happens when there are 100,000 files you need to poll?

In practice, though, the overhead is likely to be negligible whichever you do, making it hard to get excited about changing code that currently works. Best thing is to watch out for specific problems that polling causes on the system you want to change - if you find any then raise those rather than trying to make a general argument against all polling. If you don't find any, then you can't fix what isn't broken...

like image 23
Steve Jessop Avatar answered Sep 17 '22 12:09

Steve Jessop