<story><title>What happens to latency if service time is cut in half (2022)</title><url>https://pveentjer.github.io/misc/2022/04/18/service-time-cut-in-half.html</url></story><parent_chain><item><author>kqr</author><text>Another of those somewhat counter-intuitive results is the answer to the question &amp;quot;how much do we need to scale up to avoid response time regression when the request rate is doubled?&amp;quot;&lt;p&gt;It is very easy to blurt out &amp;quot;well obviously we need twice the processing power!&amp;quot; but if we scale to twice the processing power, then start accepting twice the request rate – we will actually be serving each request in half the time we originally did.&lt;p&gt;To many people that sounds weird; it sounds like we got something for nothing. If I invite twice as many people to a party and buy twice as many cookies, it&amp;#x27;s not like each guest will get twice as many cookies – that just leaves the originally planned number of cookies for each guest.&lt;p&gt;But for response time it comes back to the first equation in TFA:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    T = 1&amp;#x2F;μ · 1&amp;#x2F;(1 - ρ)
&lt;/code&gt;&lt;/pre&gt;
Doubling both arrival rate and maximum service rate leaves ρ – and the second factor with it – unchanged, but still halves the 1&amp;#x2F;μ factor, resulting in half the response time.&lt;p&gt;The appropriate amount to scale by is the k that solves the equation we get when we set the old response time T at request rate λ equal to the one at request rate 2λ and kμ processing power. This is something like&lt;p&gt;&lt;pre&gt;&lt;code&gt;    T = 1&amp;#x2F;μ · 1&amp;#x2F;(1 - λ&amp;#x2F;μ) = 1&amp;#x2F;kμ · 1&amp;#x2F;(1 - 2λ&amp;#x2F;kμ)
&lt;/code&gt;&lt;/pre&gt;
but rearranges to the much simpler&lt;p&gt;&lt;pre&gt;&lt;code&gt;    k = ρ + 1
&lt;/code&gt;&lt;/pre&gt;
which a colleague of mine told me interprets intuitively as &amp;quot;the processing power that needs to be added is exactly that which will handle an additional unit of the current utilisation on top of the current utilisation, i.e. twice as much.&amp;quot;&lt;p&gt;This is mostly good news for people doing capacity planning in advance of events etc. If you run your systems at reasonable utilisation levels normally, you don&amp;#x27;t actually need that much additional capacity to handle peak loads.</text></item></parent_chain><comment><author>mgerdts</author><text>&amp;gt; but if we scale to twice the processing power, then start accepting twice the request rate – we will actually be serving each request in half the time we originally did.&lt;p&gt;Not necessarily. If processing power is increased by doubling the clock of a processor or using a hard disk that spins and seeks twice as fast, this may be the case.&lt;p&gt;But we all know that when you have a single threaded work item, adding a second core does not cause the single threaded work to complete in half the time. If the arrival rate is substantially lower than 1&amp;#x2F;S, the second core will be of negligible value, and maybe of negative value due to synchronization overhead. This overhead is unlikely to be seen when doubling from 1 to 2, but is more likely at high levels of scaling.&lt;p&gt;If the processor is saturated, service time includes queue time, and service time is dominated by queue time, increasing processing power by doubling the number of processors may make it so that service time can almost be cut in half. How close to half depends on the ratio of queue time to processing time.</text></comment>
<story><title>What happens to latency if service time is cut in half (2022)</title><url>https://pveentjer.github.io/misc/2022/04/18/service-time-cut-in-half.html</url></story><parent_chain><item><author>kqr</author><text>Another of those somewhat counter-intuitive results is the answer to the question &amp;quot;how much do we need to scale up to avoid response time regression when the request rate is doubled?&amp;quot;&lt;p&gt;It is very easy to blurt out &amp;quot;well obviously we need twice the processing power!&amp;quot; but if we scale to twice the processing power, then start accepting twice the request rate – we will actually be serving each request in half the time we originally did.&lt;p&gt;To many people that sounds weird; it sounds like we got something for nothing. If I invite twice as many people to a party and buy twice as many cookies, it&amp;#x27;s not like each guest will get twice as many cookies – that just leaves the originally planned number of cookies for each guest.&lt;p&gt;But for response time it comes back to the first equation in TFA:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    T = 1&amp;#x2F;μ · 1&amp;#x2F;(1 - ρ)
&lt;/code&gt;&lt;/pre&gt;
Doubling both arrival rate and maximum service rate leaves ρ – and the second factor with it – unchanged, but still halves the 1&amp;#x2F;μ factor, resulting in half the response time.&lt;p&gt;The appropriate amount to scale by is the k that solves the equation we get when we set the old response time T at request rate λ equal to the one at request rate 2λ and kμ processing power. This is something like&lt;p&gt;&lt;pre&gt;&lt;code&gt;    T = 1&amp;#x2F;μ · 1&amp;#x2F;(1 - λ&amp;#x2F;μ) = 1&amp;#x2F;kμ · 1&amp;#x2F;(1 - 2λ&amp;#x2F;kμ)
&lt;/code&gt;&lt;/pre&gt;
but rearranges to the much simpler&lt;p&gt;&lt;pre&gt;&lt;code&gt;    k = ρ + 1
&lt;/code&gt;&lt;/pre&gt;
which a colleague of mine told me interprets intuitively as &amp;quot;the processing power that needs to be added is exactly that which will handle an additional unit of the current utilisation on top of the current utilisation, i.e. twice as much.&amp;quot;&lt;p&gt;This is mostly good news for people doing capacity planning in advance of events etc. If you run your systems at reasonable utilisation levels normally, you don&amp;#x27;t actually need that much additional capacity to handle peak loads.</text></item></parent_chain><comment><author>krisoft</author><text>&amp;gt; It is very easy to blurt out &amp;quot;well obviously we need twice the processing power!&amp;quot; but if we scale to twice the processing power, then start accepting twice the request rate – we will actually be serving each request in half the time we originally did.&lt;p&gt;I don&amp;#x27;t understand what you are saying. Are you talking about the time the request is buffered in some queue on average assuming they are arriving randomly? Or something like that?&lt;p&gt;Here is what I&amp;#x27;m thinking. We are operating a hospital which does only one type of surgery which last an hour exactly. (Presumably it is a veterinary practice for spherical cows.) A fully staffed operating room can operate on 24 spherical cows a day. If due to a spherical cow jamboree we expect more patients and we set up a second operating theatre we will be able to serve 48 of them a day. But we are still serving them for an hour each. (because that is how long the operation takes.)&lt;p&gt;Even if we are talking about latency when 24 cows show up at the stroke of midnight to the one operating room hospital they each will be served on average in 12.5h. Same average if 48 cows show up to the two operating room hospital.&lt;p&gt;So what am I thinking wrong here? Is &amp;quot;scale to twice the processing power&amp;quot; not the same as getting a second operating room? I&amp;#x27;m not seeing where &amp;quot;we will actually be serving each request in half the time&amp;quot; comes from.</text></comment>