I am trying to optimize what we call AJAX request polling frequency in the domain of web design. Here's a general version of the problem in simple lingo:Problem Statement:Suppose there are 3 persons - consumer (C), producer(P) and a messenger(M). The consumer and producer are some distant apart and can't communicate directly. The messenger - who works for the consumer - takes order from consumer, walks up to producer, places the order and come back to consumer. Messenger needs some finite amount of time to make the travel between P and C.Now different orders require different amount of time for processing. After an order is placed, the M and C have no way to know how long the order processing will take. Hence, the messenger is required to make repeated trips to the Producer to check if the order is ready. It works in this way:Step 1: Messenger waits for W amount of timeStep 2: M Goes to the producer to see if order is readyStep 3: a) Order ready - come back with the produced itemb) Not ready - come back and repeat from step 1.Now, I tabulated the time taken by each orders and plotted them against the number of orders taking that time. I got this:   |                |  |             25 |                |  |  |                |             |  |  |  |           20 |             |  |  |  |  |  |            |          |  |  |  |  |  |  |  |       15 |          |  |  |  |  |  |  |  |  |        |       |  |  |  |  |  |  |  |  |  |     10 |    |  |  |  |  |  |  |  |  |  |  |  |  |      | |  |  |  |  |  |  |  |  |  |  |  |  |  |  | 0  +-|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|---  1  5  10 20 25 30 35 40 45 50 55 60 65 70 75 85 90    As you can see, most orders take around 35 to 40 units of time (let's say seconds) to complete whereas some orders get completed in 5-10 seconds and some takes 80-90 seconds. My Goal:It is costly to have a high-frequency W. Right now my messenger is checking back in every W seconds. Instead of keeping this checking frequency W as constant, can we find some other checking frequency - may be a variable one where we adjust the frequency as we go along - that would ensure the least overall waiting time combining consumer and producer waiting time together.As you can tell, I am obviously not very good in articulating the problem very well. So, let me know if you need clarifications in comments.~~~ EDIT - Defining an Evaluation Model ~~~ As some of the comments suggest, it's important to include W in the evaluation model. I think what I am really trying to do here is to minimize unsuccessful pollings (like polling that comes back empty handed as producer hasn't finished producing)Say, messenger takes W amount of time to do one polling. If I take a given sample set of N pollings and if only S fractions of those polls were successful, then my intuition tells me that,S = function (N, W)So the question is - given a specific set of N, how do I find a W that maximizes S 
Algorithm to optimize polling frequency between producer and consumer
algorithms;optimization;linear programming