question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issues with the SDK

See original GitHub issue

Hello folks!

I’ve noticed a weird performance behaviour using the .Net SDK.

The test code:

[Fact]
        public async Task MultiTest()
        {
            var streamId = "Test6k";
            var toAppend = new List<Event>();
            for (int i = 0; i < 6000; i++)
            {
                toAppend.Add(new Event { StreamId = streamId, Type = "TestEvent", Payload = i.ToString() });
            }

            var sw = Stopwatch.StartNew();
            await this._storage.AppendEvents(toAppend.ToArray());
            sw.Stop();
            var appendTime = sw.ElapsedMilliseconds;
            Console.WriteLine($"Write: {appendTime}ms");

            for (int i = 0; i < 10; i++)
            {
                sw.Restart();
                var read = await this._storage.ReadStream(streamId);
                sw.Stop();
                var readTime = sw.ElapsedMilliseconds;
                Console.WriteLine($"Read: {readTime}ms");
                await Task.Delay(1000);
            }
        }

The output:

Write: 2005ms
Read: 444ms
Read: 77ms
Read: 66ms
Read: 228ms
Read: 211ms
Read: 173ms
Read: 67ms
Read: 63ms
Read: 61ms
Read: 59ms

Ignoring the Write, I’m trying to make sure the performance is consistent across Reads but from this simple test, you can see that the first Read takes 3+ times longer than the second and then in the middle it jump in again.

The SQL query being issued agains the database is:

SELECT e.id, e.SId, e.E, e.P, e.T, e.G FROM e WHERE e.id <> '_S' AND e.id <> '_H' ORDER BY e.id ASC

The partition key is being passed to the C# SDK and all the docs are from the same partition key so no cross-partition/scan is involved.

Can someone explain to me why it is so unstable the performance over this simple loop?

We are using netcoreapp3.1 with the SDK on 3.14.0.

The implementation for the ReadStream(string streamId) method on that test that encapsulate the SDK and actually make the query is this one:

var events = new List<Event>();
                var pk = new PartitionKey(streamId);

                var iterator = this._container.GetItemQueryStreamIterator(
                    GET_STREAM_QUERY,
                    requestOptions: new QueryRequestOptions { PartitionKey = pk, MaxItemCount = -1 }
                );

                do
                {
                    using ResponseMessage response = await iterator.ReadNextAsync();

                    using var result = await JsonDocument.ParseAsync(response.Content);
                    var records = result.RootElement.GetProperty(DOCUMENTS_PROP).EnumerateArray();
                    foreach (var r in records)
                    {
                        var id = r.GetProperty(EventFields.ID_FIELD).GetString();

                        var @event = new Event
                        {
                            StreamId = streamId,
                            Sequence = long.Parse(id),
                            Type = r.GetProperty(EventFields.EVENT_TYPE_FIELD).GetString(),
                            Timestamp = r.GetProperty(EventFields.TIMESTAMP_FIELD).GetDateTimeOffset(),
                        };

                        if (r.TryGetProperty(EventFields.EVENT_GROUP_FIELD, out JsonElement eg))
                        {
                            @event.Group = eg.GetString();
                        }

                        if (r.TryGetProperty(EventFields.PAYLOAD_FIELD, out JsonElement p))
                        {
                            @event.Payload = p.GetString();
                        }

                        events.Add(@event);
                    }
                } while (iterator.HasMoreResults);

Any clarifications would be appreciated.

Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ealsurcommented, Nov 9, 2020

@galvesribeiro if you see the variation on Direct mode, could you please attach the diagnostics?

For Gateway mode, there is no latency SLA, so latencies can vary. Having said that, the client-side latency can be an effect of something in the wire too.

I would advise to measure and capture performance on the production environment, on Direct mode, and see what are the numbers there. If you are experiencing high latency on Direct mode on the production machines, the diagnostics will help troubleshoot.

Unless the production machines will not be in Azure and they are the ones using the fiber connection?

0reactions
msftbot[bot]commented, Dec 15, 2021

Closing due to in-activity, pease feel free to re-open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting guide for testing with the Performance SDK
This article provides troubleshooting information for issues that you might encounter during single-user or multi-user testing that uses the ...
Read more >
Performance Impact of the Mobile SDK
The LogRocket Mobile SDK is designed to avoid a negative performance impact to your app. We're committed to keeping it that way and...
Read more >
Performance Monitoring troubleshooting and FAQ - Firebase
If you've successfully added the SDK and are using Performance Monitoring in your app, the following troubleshooting tips can help with general issues...
Read more >
Highlighting Performance Improvements Across Our Most ...
We take performance to heart when architecting our SDKs, and continuously strive to improve them.
Read more >
5 Tips to Optimize Your API's Performance
#1. Cache Requests ... Caching is one of the best ways to improve API performance. If you have requests that frequently produce the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found