NLog.Extensions.AzureTableStorage icon indicating copy to clipboard operation
NLog.Extensions.AzureTableStorage copied to clipboard

Make the log insert to azure asynchronous

Open ericlau-solid opened this issue 10 years ago • 3 comments

Since I don't see any async / await, I am assuming the current call to azure table storage to log an entry is synchronous, not asynchronous. Please make it asynchronous. Thanks.

ericlau-solid avatar Feb 06 '15 19:02 ericlau-solid

Wouldn't it be sufficient to wrap the target in an AsyncWrapper target?

DaveVdE avatar Nov 20 '15 14:11 DaveVdE

I tried. Doesn't work right. Won't log. If I remove the wrapper it works. On Nov 20, 2015 06:08, "Dave Van den Eynde" [email protected] wrote:

Wouldn't it be sufficient to wrap the target in an AsyncWrapper target?

— Reply to this email directly or view it on GitHub https://github.com/harouny/NLog.Extensions.AzureTableStorage/issues/15#issuecomment-158411109 .

ericlau-solid avatar Nov 20 '15 16:11 ericlau-solid

Interesting start but not ready for high-volume prime time. Imagine what might occur if you throw this into trace mode on a production site and there are 30 or 40 entries written for every page request and you are handling 50 or 100 page requests per second.

To accommodate something like that, the service will need to buffer entries and make block calls to Azure (storing many rows with one call to Azure). I would think something like sorted collection combined with a single put away worker thread might be in order. Another option would be to put the entries into something like Redis and have a completely separate process pull them from there and persist them to Azure Tables.

It also needs to be implemented as async/await from top to bottom otherwise the thread pool may become over taxed. You can simulate a wrapper like this:

public async Task<someType> PutSomethingAsync(string somethingToWorkOn) { someType x = await Task.Run(() => PutSomethingSync(somethingToWorkOn)); return x; } But I think you'll consume a thread every time this runs...not sure about that

If you add a buffer then a robust flush method is needed so entries in the buffer can get pushed when the hosting service shuts down.

My vote would be log to Redis and put up a separate process to persist them in cheaper storage.

bigtfromaz avatar Dec 09 '16 20:12 bigtfromaz