Skip to content

Commit

Permalink
Merge branch 'nats-io:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rickdotnet authored Mar 3, 2024
2 parents b9795bc + 56f831f commit 3377543
Show file tree
Hide file tree
Showing 89 changed files with 2,967 additions and 1,575 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
fail-fast: false
matrix:
config:
- branch: 'v2.9.22'
- branch: 'v2.10.9'
- branch: 'v2.9'
- branch: 'latest'
- branch: 'main'
runs-on: ubuntu-latest
env:
Expand All @@ -24,15 +24,20 @@ jobs:
steps:
- name: Install nats
run: |
# latest 0.1.1 doesn't have binaries
# rel=$(curl -s https://api.github.com/repos/nats-io/natscli/releases/latest | jq -r .tag_name | sed s/v//)
rel=0.1.0
rel=$(curl -s https://api.github.com/repos/nats-io/natscli/releases/latest | jq -r .tag_name | sed s/v//)
wget https://github.com/nats-io/natscli/releases/download/v$rel/nats-$rel-linux-amd64.zip
unzip nats-$rel-linux-amd64.zip
sudo mv nats-$rel-linux-amd64/nats /usr/local/bin
gh_api_url="https://api.github.com/repos/nats-io/nats-server/releases"
branch="${{ matrix.config.branch }}"
if [[ $branch == "v"* ]]; then
branch=$(curl -s $gh_api_url | jq -r '.[].tag_name' | grep $branch | sort -V | tail -1)
elif [[ $branch == "latest" ]]; then
branch=$(curl -s $gh_api_url/latest | jq -r .tag_name)
fi
for i in 1 2 3
do
curl -sf https://binaries.nats.dev/nats-io/nats-server/v2@${{ matrix.config.branch }} | PREFIX=. sh && break || sleep 30
curl -sf https://binaries.nats.dev/nats-io/nats-server/v2@$branch | PREFIX=. sh && break || sleep 30
done
sudo mv nats-server /usr/local/bin
Expand Down
26 changes: 20 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
fail-fast: false
matrix:
config:
- branch: 'v2.9.22'
- branch: 'v2.10.9'
- branch: 'v2.9'
- branch: 'latest'
- branch: 'main'
runs-on: ubuntu-latest
env:
Expand All @@ -24,9 +24,16 @@ jobs:
steps:
- name: Install nats-server
run: |
gh_api_url="https://api.github.com/repos/nats-io/nats-server/releases"
branch="${{ matrix.config.branch }}"
if [[ $branch == "v"* ]]; then
branch=$(curl -s $gh_api_url | jq -r '.[].tag_name' | grep $branch | sort -V | tail -1)
elif [[ $branch == "latest" ]]; then
branch=$(curl -s $gh_api_url/latest | jq -r .tag_name)
fi
for i in 1 2 3
do
curl -sf https://binaries.nats.dev/nats-io/nats-server/v2@${{ matrix.config.branch }} | PREFIX=. sh && break || sleep 30
curl -sf https://binaries.nats.dev/nats-io/nats-server/v2@$branch | PREFIX=. sh && break || sleep 30
done
sudo mv nats-server /usr/local/bin
Expand Down Expand Up @@ -86,8 +93,8 @@ jobs:
fail-fast: false
matrix:
config:
- branch: 'v2.9.22'
- branch: 'v2.10.9'
- branch: 'v2.9'
- branch: 'latest'
- branch: 'main'
runs-on: windows-latest
env:
Expand All @@ -109,9 +116,16 @@ jobs:
shell: bash
run: |
mkdir tools-nats-server && cd tools-nats-server
gh_api_url="https://api.github.com/repos/nats-io/nats-server/releases"
branch="${{ matrix.config.branch }}"
if [[ $branch == "v"* ]]; then
branch=$(curl -s $gh_api_url | jq -r '.[].tag_name' | grep $branch | sort -V | tail -1)
elif [[ $branch == "latest" ]]; then
branch=$(curl -s $gh_api_url/latest | jq -r .tag_name)
fi
for i in 1 2 3
do
curl -sf https://binaries.nats.dev/nats-io/nats-server/v2@${{ matrix.config.branch }} | PREFIX=. sh && break || sleep 30
curl -sf https://binaries.nats.dev/nats-io/nats-server/v2@$branch | PREFIX=. sh && break || sleep 30
done
mv nats-server nats-server.exe
cygpath -w "$(pwd)" | tee -a "$GITHUB_PATH"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ nuget/*.unitypackage
# NuGet package
/dist

# MacOS folder attributes
.DS_Store
3 changes: 3 additions & 0 deletions CODE-OF-CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Community Code of Conduct

The NATS.Net follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Contributing

Thanks for your interest in contributing! This document contains `nats-io/nats.net.v2` specific contributing details. If you are a first-time contributor, please refer to the general [NATS Contributor Guide](https://nats.io/contributing/) to get a comprehensive overview of contributing to the NATS project.

## Getting started

There are three general ways you can contribute to this repo:

- Proposing an enhancement or new feature
- Reporting a bug or regression
- Contributing changes to the source code

For the first two, refer to the [GitHub Issues](https://github.com/nats-io/nats.net.v2/issues/new/choose) which guides you through the available options along with the needed information to collect.

## Contributing Changes

_Prior to opening a pull request, it is recommended to open an issue first to ensure the maintainers can review intended changes. Exceptions to this rule include fixing non-functional source such as code comments, documentation or other supporting files._

Proposing source code changes is done through GitHub's standard pull request workflow.

If your branch is a work-in-progress then please start by creating your pull requests as draft, by clicking the down-arrow next to the `Create pull request` button and instead selecting `Create draft pull request`.

This will defer the automatic process of requesting a review from the NATS.Net team and significantly reduces noise until you are ready. Once you are happy with your PR, you can click the `Ready for review` button.

### Guidelines

A good pull request includes:

- A high-level description of the changes, including links to any issues that are related by adding comments like `Resolves #NNN` to your description. See [Linking a Pull Request to an Issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) for more information.
- An up-to-date parent commit. Please make sure you are pulling in the latest `main` branch and rebasing your work on top of it, i.e. `git rebase main`.
- Unit tests where appropriate. Bug fixes will benefit from the addition of regression tests. New features will not be accepted without suitable test coverage!
- No more commits than necessary. Sometimes having multiple commits is useful for telling a story or isolating changes from one another, but please squash down any unnecessary commits that may just be for clean-up, comments or small changes.
- No additional external dependencies that aren't absolutely essential. Please do everything you can to avoid pulling in additional libraries/dependencies as we will be very critical of these.

## Get Help

If you have questions about the contribution process, please start a [GitHub discussion](https://github.com/nats-io/nats.net.v2/discussions) or join the [NATS Slack](https://slack.nats.io/).
Binary file modified Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![License Apache 2.0](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![NuGet](https://img.shields.io/nuget/v/NATS.Net.svg?cacheSeconds=3600)](https://www.nuget.org/packages/NATS.Net)

# NATS.Net

[NATS](https://nats.io) client for modern [.NET](https://dot.net/).
Expand Down Expand Up @@ -35,6 +38,8 @@ Check out the [documentation](https://nats-io.github.io/nats.net.v2/) for guides

Find us on [slack.nats.io dotnet channel](https://natsio.slack.com/channels/dotnet)

Please also check out the [Contributor Guide](CONTRIBUTING.md) and [Code of Conduct](CODE-OF-CONDUCT.md).

## Attribution

This library is based on the excellent work in [Cysharp/AlterNats](https://github.com/Cysharp/AlterNats)
1 change: 1 addition & 0 deletions sandbox/BlazorWasm/Client/BlazorWasm.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\src\NATS.Client.Hosting\NATS.Client.Hosting.csproj" />
<ProjectReference Include="..\..\..\src\NATS.Client.Serializers.Json\NATS.Client.Serializers.Json.csproj" />
<ProjectReference Include="..\Shared\BlazorWasm.Shared.csproj" />
</ItemGroup>

Expand Down
8 changes: 7 additions & 1 deletion sandbox/BlazorWasm/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using NATS.Client.Core;
using NATS.Client.Hosting;
using NATS.Client.Serializers.Json;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddNats(configureOpts: opt => opt with { Url = "ws://localhost:4280", Name = "BlazorClient" });
builder.Services.AddNats(configureOpts: opt => opt with
{
SerializerRegistry = NatsJsonSerializerRegistry.Default,
Url = "ws://localhost:8080",
Name = "BlazorClient",
});

await builder.Build().RunAsync();
8 changes: 7 additions & 1 deletion sandbox/BlazorWasm/Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using BlazorWasm.Server.NatsServices;
using NATS.Client.Core;
using NATS.Client.Hosting;
using NATS.Client.Serializers.Json;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddNats(configureOpts: opt => opt with { Url = "localhost:4222", Name = "BlazorServer" });
builder.Services.AddNats(configureOpts: opt => opt with
{
SerializerRegistry = NatsJsonSerializerRegistry.Default,
Url = "localhost:4222",
Name = "BlazorServer",
});
builder.Services.AddHostedService<WeatherForecastService>();

var app = builder.Build();
Expand Down
26 changes: 26 additions & 0 deletions sandbox/MicroBenchmark/NKeyBench.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BenchmarkDotNet.Attributes;
using NATS.Client.Core;

namespace MicroBenchmark;

[ShortRunJob]
[MemoryDiagnoser]
[PlainExporter]
public class NKeyBench
{
[Params(5000)]
public int Iter { get; set; }

[Benchmark]
public int NKeyCreate()
{
var result = 0;
for (var i = 0; i < Iter; i++)
{
var nkey = NKeys.FromSeed("SUAAVWRZG6M5FA5VRRGWSCIHKTOJC7EWNIT4JV3FTOIPO4OBFR5WA7X5TE");
result += nkey.PublicKey.Length;
}

return result;
}
}
89 changes: 89 additions & 0 deletions sandbox/MicroBenchmark/PublishParallelBench.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System.Text.Json.Serialization;
using BenchmarkDotNet.Attributes;
using NATS.Client.Core;

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

namespace MicroBenchmark;

[MemoryDiagnoser]
[ShortRunJob]
[PlainExporter]
public class PublishParallelBench
{
public const int TotalMsgs = 1_000_000;

private static readonly PublishParallelObj Data = new PublishParallelObj
{
String = new('a', 32),
Bool = true,
Int = 42,
Dictionary = new Dictionary<string, string>
{
{ new('a', 32), new('a', 32) },
{ new('b', 32), new('b', 32) },
{ new('c', 32), new('c', 32) },
},
List = new List<string>
{
new('a', 32),
new('b', 32),
new('c', 32),
},
};

private NatsConnection _nats;

[Params(1, 2, 4)]
public int Concurrency { get; set; }

[GlobalSetup]
public async Task Setup()
{
var registry = new NatsJsonContextSerializerRegistry(PublishParallelJsonContext.Default);
_nats = new NatsConnection(NatsOpts.Default with { SerializerRegistry = registry });
await _nats.ConnectAsync();
}

[Benchmark]
public async Task PublishParallelAsync()
{
var tasks = new List<Task>();
for (var i = 0; i < Concurrency; i++)
{
tasks.Add(Task.Run(async () =>
{
for (var j = 0; j < TotalMsgs / Concurrency; j++)
{
await _nats.PublishAsync("test", Data);
}
}));
}

await Task.WhenAll(tasks);
await _nats.PingAsync();
}
}

internal record PublishParallelObj
{
[JsonPropertyName("string")]
public string String { get; set; }

[JsonPropertyName("bool")]
public bool Bool { get; set; }

[JsonPropertyName("int")]
public int Int { get; set; }

[JsonPropertyName("dictionary")]
public Dictionary<string, string> Dictionary { get; set; }

[JsonPropertyName("list")]
public List<string> List { get; set; }
}

[JsonSerializable(typeof(PublishParallelObj))]
internal partial class PublishParallelJsonContext : JsonSerializerContext
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MicroBenchmark;
[MemoryDiagnoser]
[ShortRunJob]
[PlainExporter]
public class SerializationBuffersBench
public class PublishSerialBench
{
private static readonly string Data = new('0', 126);

Expand All @@ -17,16 +17,20 @@ public class SerializationBuffersBench
public int Iter { get; set; }

[GlobalSetup]
public void Setup() => _nats = new NatsConnection();
public async Task SetupAsync()
{
_nats = new NatsConnection();
await _nats.ConnectAsync();
}

[Benchmark]
public async ValueTask<TimeSpan> PublishAsync()
public async Task PublishAsync()
{
for (var i = 0; i < Iter; i++)
{
await _nats.PublishAsync("foo", Data);
}

return await _nats.PingAsync();
await _nats.PingAsync();
}
}
39 changes: 39 additions & 0 deletions sandbox/MicroBenchmark/Sha512Bench.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BenchmarkDotNet.Attributes;
using NATS.Client.Core.NaCl;

namespace MicroBenchmark;

[ShortRunJob]
[MemoryDiagnoser]
[PlainExporter]
public class Sha512TBench
{
private byte[] _data = default!;

[Params(5000)]
public int Iter { get; set; }

[Params(1024, 1024 * 25)]
public int DataSize { get; set; }

[GlobalSetup]
public void Setup()
{
var random = new Random(4711);
_data = new byte[DataSize];
random.NextBytes(_data);
}

[Benchmark]
public int Sha512Hash()
{
var result = 0;
for (var i = 0; i < Iter; i++)
{
var hash = Sha512.Hash(_data, 0, _data.Length)!;
result += hash.Length;
}

return result;
}
}
Loading

0 comments on commit 3377543

Please sign in to comment.