Skip to content

Commit

Permalink
Follow Nexus changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Mar 15, 2024
1 parent 249e357 commit 19badeb
Show file tree
Hide file tree
Showing 23 changed files with 1,051 additions and 1,096 deletions.
29 changes: 25 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
# How to format:
# (1) Add dotnet_diagnostic.XXXX.severity = error
# (2) Run dotnet-format: dotnet format --diagnostics XXXX
# How to apply single rule:
# Run dotnet format --diagnostics XXXX --severity info

# How to apply all rules:
# Run dotnet format --severity error/info/warn/

[*]
trim_trailing_whitespace = true

[*.cs]
# "run cleanup": https://betterprogramming.pub/enforce-net-code-style-with-editorconfig-d2f0d79091ac
# TODO: build real editorconfig file: https://github.com/dotnet/roslyn/blob/main/.editorconfig
# TODO: build real editorconfig file: https://github.com/dotnet/roslyn/blob/main/.editorconfig

# Prefer var
csharp_style_var_for_built_in_types = false
csharp_style_var_when_type_is_apparent = true
csharp_style_var_elsewhere = true
dotnet_diagnostic.IDE0007.severity = warning

# Make field
dotnet_diagnostic.IDE0044.severity = warning

# Use file scoped namespace declarations
dotnet_diagnostic.IDE0161.severity = error
csharp_style_namespace_declarations = file_scoped

# Collection initialization can be simplified
dotnet_diagnostic.IDE0300.severity = warning

# Enable naming rule violation errors on build (alternative: dotnet_analyzer_diagnostic.category-Style.severity = error)
dotnet_diagnostic.IDE1006.severity = error
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ jobs:
- name: Build
run: |
dotnet build -c Release /p:GeneratePackage=true src/remoting/dotnet-remoting/dotnet-remoting.csproj
python -m build --wheel --outdir artifacts/packages --no-isolation src/remoting/python-remoting
python -m build --wheel --outdir artifacts/package --no-isolation src/remoting/python-remoting
- name: Test
run: |
dotnet test -c Release --filter TestCategory=local
pyright
pytest
sudo bash tests/Nexus.Sources.Remote.Tests/SetupDockerTests.sh
# sudo bash tests/Nexus.Sources.Remote.Tests/SetupDockerTests.sh
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
artifacts/tag_body.txt
artifacts/packages/
artifacts/package/release/
outputs:
is_release: ${{ env.IS_RELEASE }}
Expand All @@ -94,13 +94,13 @@ jobs:

# GitHub Package Registry is broken by design: https://github.community/t/download-from-github-package-registry-without-authentication/14407/138
- name: Nuget package (MyGet)
run: dotnet nuget push 'artifacts/packages/*.nupkg' --api-key ${MYGET_API_KEY} --source https://www.myget.org/F/apollo3zehn-dev/api/v3/index.json
run: dotnet nuget push 'artifacts/package/release/*.nupkg' --api-key ${MYGET_API_KEY} --source https://www.myget.org/F/apollo3zehn-dev/api/v3/index.json
env:
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}

# GitHub Package Registry does not support Python packages: https://github.community/t/pypi-compatible-github-package-registry/14615
- name: Python package (MyGet)
run: 'for filePath in artifacts/packages/*.whl; do curl -k -X POST https://www.myget.org/F/apollo3zehn-dev/python/upload -H "Authorization: Bearer ${MYGET_API_KEY}" -F "data=@$filePath"; done'
run: 'for filePath in artifacts/package/*.whl; do curl -k -X POST https://www.myget.org/F/apollo3zehn-dev/python/upload -H "Authorization: Bearer ${MYGET_API_KEY}" -F "data=@$filePath"; done'
env:
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}

Expand Down Expand Up @@ -130,11 +130,11 @@ jobs:
body_path: artifacts/tag_body.txt

- name: Nuget package (Nuget)
run: dotnet nuget push 'artifacts/packages/*.nupkg' --api-key ${NUGET_API_KEY} --source https://api.nuget.org/v3/index.json
run: dotnet nuget push 'artifacts/package/release/*.nupkg' --api-key ${NUGET_API_KEY} --source https://api.nuget.org/v3/index.json
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}

- name: Python Package (PyPI)
run: twine upload artifacts/packages/*.whl -u__token__ -p"${PYPI_API_KEY}"
run: twine upload artifacts/package/*.whl -u__token__ -p"${PYPI_API_KEY}"
env:
PYPI_API_KEY: ${{ secrets.PYPI_API_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vs/
.venv/

artifacts/
BenchmarkDotNet.Artifacts

Expand Down
21 changes: 0 additions & 21 deletions .vscode/launch.json

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.0.0-beta.24 - 2024-03-15

- Follow Nexus changes.

## v2.0.0-beta.2 - 2023-09-26

Follow Nexus changes.
Expand Down
12 changes: 3 additions & 9 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworkVersion>net7.0</TargetFrameworkVersion>
<TargetFrameworkVersion>net8.0</TargetFrameworkVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<LangVersion>latest</LangVersion>
<RestoreAdditionalProjectSources>
https://www.myget.org/F/apollo3zehn-dev/api/v3/index.json
</RestoreAdditionalProjectSources>
</PropertyGroup>

<PropertyGroup>
<ArtifactsPath>$([MSBuild]::NormalizePath($(MSBuildThisFileDirectory)artifacts))</ArtifactsPath>
<BaseIntermediateOutputPath>$(ArtifactsPath)/obj/$(MSBuildProjectName)</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)/$(Configuration)</IntermediateOutputPath>
<OutputPath>$(ArtifactsPath)/bin/$(MSBuildProjectName)/$(Configuration)</OutputPath>
<PackageOutputPath>$(ArtifactsPath)/packages</PackageOutputPath>
<UseArtifactsOutput>true</UseArtifactsOutput>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion benchmarks/Nexus.Benchmarks/Nexus.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>

</Project>
185 changes: 92 additions & 93 deletions benchmarks/Nexus.Benchmarks/PipeVsTcp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,117 +6,116 @@
using System.Reflection;
using System.Runtime.InteropServices;

namespace Nexus.Benchmarks
namespace Nexus.Benchmarks;

[MemoryDiagnoser]
public class PipeVsTcp
{
[MemoryDiagnoser]
public class PipeVsTcp
private Process _pipeProcess = default!;
private Process _tcpProcess = default!;
private TcpClient _tcpClient = default!;

[GlobalSetup]
public void GlobalSetup()
{
private Process _pipeProcess = default!;
private Process _tcpProcess = default!;
private TcpClient _tcpClient = default!;
// assembly path
var assemblyPath = Assembly.GetExecutingAssembly().Location;

[GlobalSetup]
public void GlobalSetup()
// run pipe process
var pipePsi = new ProcessStartInfo("dotnet")
{
// assembly path
var assemblyPath = Assembly.GetExecutingAssembly().Location;

// run pipe process
var pipePsi = new ProcessStartInfo("dotnet")
{
Arguments = $"{assemblyPath} pipe",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

_pipeProcess = new Process() { StartInfo = pipePsi };
_pipeProcess.Start();

// run tcp process
var tcpPsi = new ProcessStartInfo("dotnet")
{
Arguments = $"{assemblyPath} tcp",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

_tcpProcess = new Process() { StartInfo = tcpPsi };
_tcpProcess.Start();

var tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 55555);
tcpListener.Start();

_tcpClient = tcpListener.AcceptTcpClient();
_tcpClient.NoDelay = true;
}

[GlobalCleanup]
public void GlobalCleanup()
Arguments = $"{assemblyPath} pipe",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

_pipeProcess = new Process() { StartInfo = pipePsi };
_pipeProcess.Start();

// run tcp process
var tcpPsi = new ProcessStartInfo("dotnet")
{
_pipeProcess?.Kill();
_tcpProcess?.Kill();
}
Arguments = $"{assemblyPath} tcp",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

[Params(Program.MIN_LENGTH, 100, 10_000, 1_000_000, Program.MAX_LENGTH)]
public int N;
_tcpProcess = new Process() { StartInfo = tcpPsi };
_tcpProcess.Start();

[Benchmark(Baseline = true)]
public Memory<byte> Pipe()
{
var pipeReadStream = _pipeProcess.StandardOutput.BaseStream;
var pipeWriteStream = _pipeProcess.StandardInput.BaseStream;
using var owner = MemoryPool<byte>.Shared.Rent(N * sizeof(int));
var tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 55555);
tcpListener.Start();

return ReadFromStream(pipeReadStream, pipeWriteStream, owner.Memory);
}
_tcpClient = tcpListener.AcceptTcpClient();
_tcpClient.NoDelay = true;
}

[Benchmark()]
public Memory<byte> Tcp()
{
var tcpReadStream = _tcpClient.GetStream();
var pipeWriteStream = _tcpProcess.StandardInput.BaseStream;
using var owner = MemoryPool<byte>.Shared.Rent(N * sizeof(int));
[GlobalCleanup]
public void GlobalCleanup()
{
_pipeProcess?.Kill();
_tcpProcess?.Kill();
}

return ReadFromStream(tcpReadStream, pipeWriteStream, owner.Memory);
}
[Params(Program.MIN_LENGTH, 100, 10_000, 1_000_000, Program.MAX_LENGTH)]
public int N;

private Memory<byte> ReadFromStream(Stream readStream, Stream writeStream, Memory<byte> buffer)
{
// trigger
var Nbuffer = BitConverter.GetBytes(N);
writeStream.Write(Nbuffer);
writeStream.Flush();
[Benchmark(Baseline = true)]
public Memory<byte> Pipe()
{
var pipeReadStream = _pipeProcess.StandardOutput.BaseStream;
var pipeWriteStream = _pipeProcess.StandardInput.BaseStream;
using var owner = MemoryPool<byte>.Shared.Rent(N * sizeof(int));

return ReadFromStream(pipeReadStream, pipeWriteStream, owner.Memory);
}

[Benchmark()]
public Memory<byte> Tcp()
{
var tcpReadStream = _tcpClient.GetStream();
var pipeWriteStream = _tcpProcess.StandardInput.BaseStream;
using var owner = MemoryPool<byte>.Shared.Rent(N * sizeof(int));

return ReadFromStream(tcpReadStream, pipeWriteStream, owner.Memory);
}

// receive data
var remaining = N * sizeof(int);
var offset = 0;
private Memory<byte> ReadFromStream(Stream readStream, Stream writeStream, Memory<byte> buffer)
{
// trigger
var Nbuffer = BitConverter.GetBytes(N);
writeStream.Write(Nbuffer);
writeStream.Flush();

while (remaining > 0)
{
var span = buffer.Slice(offset, remaining).Span;
var readBytes = readStream.Read(span);
// receive data
var remaining = N * sizeof(int);
var offset = 0;

if (readBytes == 0)
throw new Exception("The child process terminated early.");
while (remaining > 0)
{
var span = buffer.Slice(offset, remaining).Span;
var readBytes = readStream.Read(span);

remaining -= readBytes;
offset += readBytes;
}
if (readBytes == 0)
throw new Exception("The child process terminated early.");

var intBuffer = MemoryMarshal.Cast<byte, int>(buffer.Span);
remaining -= readBytes;
offset += readBytes;
}

// validate first 3 values
for (int i = 0; i < Math.Min(N, 3); i++)
{
if (intBuffer[i] != i)
throw new Exception($"Invalid data received. Data is {intBuffer[i]}, index = {i}.");
}
var intBuffer = MemoryMarshal.Cast<byte, int>(buffer.Span);

return buffer;
// validate first 3 values
for (int i = 0; i < Math.Min(N, 3); i++)
{
if (intBuffer[i] != i)
throw new Exception($"Invalid data received. Data is {intBuffer[i]}, index = {i}.");
}

return buffer;
}
}
Loading

0 comments on commit 19badeb

Please sign in to comment.