text
stringlengths
0
1.8k
[1698.44 --> 1706.78] And so instead of recording everything that's happening, as I said earlier, we only look at the stack traces 100 times per second.
[1707.04 --> 1708.98] And that we can do incredibly efficiently.
[1709.54 --> 1717.96] The reason why this is super useful and why being able to record stack traces with statistical significance is useful is that now we can say,
[1718.12 --> 1721.54] this is where my program is spending time.
[1721.54 --> 1726.18] And so that can be used to save money on your infrastructure.
[1726.62 --> 1735.88] But also, you know, there are a lot of optimizations that you can only do if you have that type of depth of data to analyze.
[1736.18 --> 1741.92] So you can actually down to the line number tell what is using your CPU resources.
[1742.26 --> 1748.64] One really cool conversation that I had yesterday, this perfectly translates in the serverless world, right?
[1748.64 --> 1755.88] Where you actually pay for basically every single CPU cycle that your serverless function is running.
[1756.24 --> 1763.16] And any CPU second that you can cut off from that is money you're saving from your serverless bill.
[1763.72 --> 1767.96] And so I think that's a really obvious value proposition.
[1768.40 --> 1777.54] Because we simply have this data and are recording it always, we can actually reliably tell where we can optimize our code.
[1777.54 --> 1782.14] So out of these three things, saving money, very important for some.
[1782.64 --> 1784.78] Improving performance, I love that.
[1785.36 --> 1787.76] Like shipping code fast, great.
[1788.28 --> 1790.82] Making it better and improving it, I love that.
[1791.34 --> 1795.44] And when things go wrong, understanding what exactly went wrong.
[1796.16 --> 1800.90] What CPU, what disk, what network, where is the bottleneck from a system perspective,
[1801.16 --> 1805.14] as well as obviously from like if you have microservices, between microservices.
[1805.14 --> 1811.82] So Parca helps us understand from a CPU perspective, where is the time spent, right?
[1811.86 --> 1815.58] In the current implementation, the current version, that's what it tells us really, really well.
[1815.96 --> 1817.08] So how about we try it out?
[1817.54 --> 1820.42] We're going to run it in our production Kubernetes setup.
[1820.86 --> 1822.14] Just like that, why not?
[1822.72 --> 1826.36] Create namespace, apply the server, and apply the agent.
[1827.02 --> 1830.70] And as I do this in the background, what is the difference, Frederick, between the server and the agent?
[1830.70 --> 1836.94] The server is essentially the component that allows you to store and query profiling data.
[1837.72 --> 1847.38] While the agent, the one and only purpose of the agent is to capture this data from your applications at super low overhead.
[1848.00 --> 1852.10] And one of the really exciting technologies that we're using here is EVPF.
[1852.10 --> 1862.54] So because we know exactly what the format is that we're going to want this type of data in, we can, in kernel, you know,
[1862.60 --> 1868.48] without having to spend all of this overhead of doing context switches from kernel space to user space,
[1868.70 --> 1876.20] we can immediately record the stack traces in kernel and present it to Parca agent.
[1876.20 --> 1883.56] And then Parca agent, it does some resorting in the data, but essentially it just sends that off to Parca.
[1883.88 --> 1885.88] And then from Parca, you can actually visualize it.
[1886.18 --> 1886.24] Okay.
[1886.64 --> 1888.70] So we have the server and the agent.
[1889.44 --> 1892.84] So let's port forward to the server, to the UI.
[1893.98 --> 1898.40] And in our browser, localhost 7070, let's see what that looks like.
[1898.58 --> 1904.12] One thing that I think is really important to mention, everything revolves around the PPF standard.
[1904.12 --> 1908.16] This is kind of an industry standard format for profiling data.
[1909.28 --> 1914.18] And so everything produces or works with PPF format.
[1914.40 --> 1925.32] So you could send any kind of profile, like memory profiles that have been captured through some other mechanism to Parca and analyze that as well.
[1925.64 --> 1931.84] It's just that the agent today can only produce CPU profiles and continuously send those.
[1931.84 --> 1936.58] The agent actually also produces PPF compatible profiles.
[1936.82 --> 1938.40] And maybe we can have a look at that later.
[1939.36 --> 1941.02] The server ingests those.
[1941.28 --> 1949.88] And then one additional really cool feature, I think, is any query that you do in the Parca front end, you can download again in PPF format.
[1950.18 --> 1956.94] And then, you know, if you have any other sort of tooling around the PPF format, you can still use them and compose your workflows.
[1956.94 --> 1961.82] Okay, we are on the server looking at all the CPU profiles.
[1962.02 --> 1964.78] This is the profile coming from container Parca.
[1965.30 --> 1966.68] How do we read this?
[1966.94 --> 1968.04] It's a CPU sample.
[1968.40 --> 1969.36] We can see the root.
[1969.60 --> 1970.80] That's the root span.
[1971.40 --> 1972.90] What about all the other spans?
[1973.14 --> 1973.70] What are these?
[1973.70 --> 1975.58] This is what's called a flame graph.
[1975.86 --> 1985.68] And every span that we're seeing here represents how much this span as well as all of its children make up in cumulative.
[1986.20 --> 1988.92] So that's actually what the front end also says, right?
[1988.98 --> 1990.12] The cumulative value.
[1990.94 --> 1995.32] And essentially we're saying everything from this point onwards and further down uses up.
[1995.68 --> 1997.70] In this case, you're hovering over one that says 11%.
[1997.70 --> 2003.98] So, for example, we can see here in the middle, we can see runtime.grayobject, for example.
[2004.26 --> 2017.34] If we were able to optimize that gray object function, for example, and say for whatever reason we're able to optimize 100% of it away, we would actually be saving 15% of our CPU resources here.
[2017.34 --> 2027.08] And in this case, you actually clicked a particularly interesting sample because we can see in our metrics above that we have these spikes every now and then.
[2027.30 --> 2032.76] And we can very clearly see what it is that is causing the spike in this profile.
[2033.04 --> 2036.40] We can see that it's garbage collection, right?
[2036.44 --> 2040.06] A very classic thing that can use a lot of CPU resources.
[2040.48 --> 2044.38] So this is garbage collection that happens in Parca server, okay?
[2044.88 --> 2046.42] So why does this garbage collection happen?
[2046.42 --> 2052.46] Because of how Go works, you allocate objects in memory.
[2053.02 --> 2066.50] And when you don't use them anymore, eventually the runtime will come around and see that this piece of memory is not in use anymore and kind of free that memory to the operating system so that anybody on the machine can use it.
[2066.50 --> 2075.78] And in this case, essentially what we're seeing, because we have such a huge spike, that's telling us Parca is doing a lot of allocations.
[2075.98 --> 2083.08] It's allocating a lot of memory that then consequently is kind of thrown away and can be garbage collected.
[2083.08 --> 2087.90] So it seems like there's probably some potential in optimizing allocations here.
[2088.00 --> 2097.10] That said, having allocations is not a bad thing because at the end of the day, I can write a program that does absolutely nothing and does no allocations, right?
[2097.14 --> 2098.24] But that's also not useful.
[2098.72 --> 2103.52] Producing side effect is one of those things that as software engineers, we try to not produce side effect.
[2103.52 --> 2108.30] But as it turns out, side effect tends to be the thing that's actually useful in the real world.
[2108.44 --> 2110.18] That's when real work happens, right?
[2110.26 --> 2114.42] Like these spikes are an artifact of real work happening.
[2114.42 --> 2129.48] And if I had to guess without knowing too much, knowing what Parca does behind the scenes, but not knowing all the details, I think that this is related to all those profiles being maybe read, being symbolized, or something happens in the background.
[2129.48 --> 2135.28] So like reads a profile, builds whatever data structures it needs to build to get an output.
[2135.28 --> 2142.40] And when that output is like that result, right, is achieved, then all the intermediary objects can be garbage collected.
[2142.50 --> 2143.78] And I think that's what's happening here.
[2143.78 --> 2151.80] The two major things are definitely what you already mentioned, symbolization, because this happens asynchronously as you have uploaded your profiling data.
[2151.98 --> 2156.60] And then it's actually ingesting and writing that profiling data to its storage.
[2156.60 --> 2160.94] This is something that because we're doing continuous profiling, it happens continuously, right?
[2161.20 --> 2169.12] And every network request that we receive causes memory allocations because we read that from the network stack, right?
[2169.16 --> 2170.78] And that causes memory allocations.
[2170.78 --> 2176.04] Now, there are a number of optimizations that can be done to reduce this.
[2176.18 --> 2178.72] And, you know, you can reuse buffers and stuff like that.
[2178.72 --> 2183.78] And we'll get to all of that, but it's unlikely that we'll ever get to, you know, zero.
[2184.06 --> 2186.56] But there's definitely lots of optimization potential here.
[2187.00 --> 2187.24] Okay.
[2187.52 --> 2191.52] I do have to say, looking at this flame graph, it's really amazing.
[2192.08 --> 2206.58] Like if you remember how difficult this used to be in the past where you had to generate a pprof and then use that pprof or something similar that can read that profile to get this flame graph and then try and like slice and dice.
[2206.58 --> 2209.50] Now, if I don't want this flame graph, I want a different one.
[2209.68 --> 2210.80] I just click on it.
[2211.54 --> 2212.44] And there you go.