Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

limited scalability returning JSON due to ArrayPool contention #4660

Closed
nathana1 opened this issue May 17, 2016 · 9 comments
Closed

limited scalability returning JSON due to ArrayPool contention #4660

nathana1 opened this issue May 17, 2016 · 9 comments
Assignees

Comments

@nathana1
Copy link

When running an mvc json benchmark (https://github.com/aspnet/benchmarks/blob/dev/src/Benchmarks/Controllers/HomeController.cs#L22) on a 48 core machine I'm unable to get above 75% cpu with profiles showing a lot of time blocked in Rent and Return in System.Buffers.DefaultArrayPool.

The issue appears to be that the ArrayPool partitions its locks based on buffer size (

return new HttpResponseStreamWriter(stream, encoding, DefaultBufferSize, _bytePool, _charPool);
) and only one size of buffer is requested from the byte and char pools (
return new HttpResponseStreamWriter(stream, encoding, DefaultBufferSize, _bytePool, _charPool);
), so all requests will wait on one bucket.

We seem to need another level of indirection/partitioning here, not sure if MVC or the ArrayPool is the best place.

@nathana1 nathana1 added the Perf label May 17, 2016
@nathana1 nathana1 self-assigned this May 17, 2016
@rynowak
Copy link
Member

rynowak commented May 17, 2016

/cc @KrzysztofCwalina @stephentoub @jonmiller

@nathana1 - how many RPS is this running at?

We did some investigations here in the past but didn't encounter a scenario where the contention was significant after making some changes to fix it. https://github.com/dotnet/corefx/issues/7727

@nathana1
Copy link
Author

This is about 400k rps.

@Eilon Eilon added this to the 1.0.1 milestone May 19, 2016
@Eilon
Copy link
Member

Eilon commented May 19, 2016

Parking this in post-v1 for now. When we have more data we can figure out when exactly to take a change related to this.

@rynowak
Copy link
Member

rynowak commented Jul 5, 2016

@nathana1 it's probably a good time to start taking a look at this now.

What kind of data do we have that points to the array pool as an issue?

Do we know for sure that we were using the implementation of ArrayPool<> with the fix for https://github.com/dotnet/corefx/issues/7727 ? Note that we did not ship the fixed version of this in RC2.

@nathana1
Copy link
Author

nathana1 commented Jul 6, 2016

This still repro's in the rtm bits. I'm working on some profiles and I'll send them to you.

@nathana1
Copy link
Author

Hi @rynowak,

In the various profiles I'm seeing 5-10% spent in spinning in the ArrayPool and the thread time profiles show another 5% spent sleeping in those same locks.

I did a quick and dirty prototype (nathana1/corefx@b5ae2a9) where I partition the ArrayPool buckets into subbuckets and lock at that level instead, I see throughput go from 330k rps to 460k rps (and cpu saturation).

/cc @stephentoub @sajaya @sivagms

@Eilon Eilon modified the milestones: 1.1.0-preview1, 1.1.0 Oct 6, 2016
@Eilon Eilon assigned rynowak and unassigned nathana1 Oct 24, 2016
@Eilon
Copy link
Member

Eilon commented Oct 24, 2016

@rynowak can you follow up with @davidfowl on what we wish to do here?

@Eilon Eilon modified the milestones: 1.1.0, 1.2.0 Nov 8, 2016
@stephentoub
Copy link

Is this still an issue after dotnet/coreclr#8209 ?

@rynowak
Copy link
Member

rynowak commented Dec 6, 2016

Yeah. We should close this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants