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

Use pipelines for SocketOutput #1497

Closed
wants to merge 22 commits into from
Closed

Use pipelines for SocketOutput #1497

wants to merge 22 commits into from

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Mar 17, 2017

  • Changed socket output to be based on pipelines
  • Changed connection filter glue to be based on pipelines
  • Codegen that used MemoryPoolIterator for output now uses WritableBuffer
  • Made UvWriteReq async/await friendly with LibuvAwaitable<T>
  • Deleted MemoryPool and friends

TODO:

/cc @pakrym

pakrym and others added 15 commits March 17, 2017 04:42
- Removed shutdown bools
- Use LibuvAwaitable instead of having all of that
state on the UvWriteReq
- Remove Console output from TestApplicationErrorLogger
- Reduce the lock in output to avoid deadlocks
- Pin memory instead of using TryGetPointer in UvWriteReq

listenOptions.UseConnectionLogging();
// listenOptions.UseConnectionLogging();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will revert

MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0,
MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0
};

public PipeOptions AdaptedPipeOptions => new PipeOptions
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some tweaking. We don't want request limits for both pipes in the adapter.

@@ -86,5 +89,19 @@ public static ArraySegment<byte> GetArray(this Memory<byte> memory)
}
return result;
}

public static void WriteAscii(this WritableBuffer buffer, string data)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be optimized /cc @benaadams 😄


public static void WriteNumeric(this WritableBuffer buffer, ulong number)
{
buffer.Write(number.ToString());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf?

Debug.Assert(tryGetPointerResult);
// REVIEW: This isn't necessary for our default pool since the memory is
// already pinned but it also makes tests pass
var memoryHandle = memory.Pin();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test is wrong, passing ReadableBuffer.Create result which is array based and unexpected. We should just change the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't wrong, just unnecessary if we were to use pre pinned buffers. I also think the overhead is negligible

@@ -17,7 +16,7 @@ public class TestApplicationErrorLogger : ILogger

public bool ThrowOnCriticalErrors { get; set; } = true;

public List<LogMessage> Messages { get; } = new List<LogMessage>();
public ConcurrentBag<LogMessage> Messages { get; } = new ConcurrentBag<LogMessage>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going for eventually consistent model 😆

ConcurrentQueue?

adapterContext.ConnectionStream,
Thread.PipelineFactory.Create(ListenerContext.AdaptedPipeOptions),
Thread.Memory,
Log);
Thread.PipelineFactory.Create(ListenerContext.AdaptedPipeOptions));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use named args here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't tell what is what.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only do that for bools and null args.

{
public class LibuvAwaitable<TRequest> : ICriticalNotifyCompletion where TRequest : UvRequest
{
private readonly static Action CALLBACK_RAN = () => { };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHY CAPS

//namespace Microsoft.AspNetCore.Server.KestrelTests
//{
// public class SocketOutputTests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it works? :trollface:

ReaderScheduler = Thread,
WriterScheduler = ServiceContext.ThreadPool,
MaximumSizeHigh = ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0,
MaximumSizeLow = ServiceContext.ServerOptions.Limits.MaxResponseBufferSize ?? 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a new option is needed.

Self._head = null;
Self._tail = null;
returnAll = true;
// REVIEW: Locking here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
{
public class LibuvAwaitable<TRequest> : ICriticalNotifyCompletion where TRequest : UvRequest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: put where clause in it's own line


public struct UvWriteResult
{
public int Status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly


private int _status;

public static Action<TRequest, int, Exception, object> Callback = (req, status, error, state) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly

Input = pipe;
Output = new StreamSocketOutput(connectionId, filteredStream, memory, logger);
Input = inputPipe;
_output = new StreamSocketOutput(filteredStream, outputPipe);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge StreamSocketOutput into AdaptedPipeline

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next round

if (buffer.IsEmpty)
{
await _outputStream.FlushAsync();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else?

{
TaskCompletionSource<object> tcs = null;
var scheduleWrite = false;
var flushAwaiter = default(WritableBufferAwaitable);
Copy link
Contributor

@pakrym pakrym Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WritableBufferAwaitable flushAwaiter;

socketShutdownSend: false,
socketDisconnect: true,
isSync: true);
// Not graceful
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turn switch to if?

@davidfowl
Copy link
Member Author

Will make all of the nit feedback in a subsequent commit.

@davidfowl
Copy link
Member Author

This is merged

@davidfowl davidfowl closed this Mar 18, 2017
@cesarblum
Copy link
Contributor

07cbf7f

@davidfowl davidfowl deleted the pakrym/pipe-output branch March 21, 2017 07:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants