I want to run a simple .net 6 c# consumption azure function app (not durable) every minute, but I need to remember the state from the previous run.
The state consists of arrays of json serializable objects, and a few access token strings.
So I create a durable function entity like this:
[JsonObject(MemberSerialization.OptIn)]
public class DurableStorageEntity
{
[JsonProperty("simpledata")]
public string SimpleData { get; set; }
[JsonProperty("complicateddata")]
public List<ComplicatedObject> ComplicatedData { get; set; }
public void SetSimpleData(string data) => this.SimpleData = data;
public void SetComplicatedObject(List<ComplicatedObject> data) => this.ComplicatedObject = data;
[FunctionName(nameof(DurableStorageEntity))]
public static Task Run([EntityTrigger] IDurableEntityContext ctx)
=> ctx.DispatchAsync<DurableStorageEntity>();
}
This works great, but I am unsure how efficient this is and how much state data I can store this way. After testing I am also unsure if this is reliable when called from a regular (i.e. non durable) function app.
I can't find any clear information on this. In the MS document on Entity Functions it simply states:
Entity functions define operations for reading and updating small pieces of state, known as durable entities.
And
Entities provide a means for scaling out applications by distributing the work across many entities, each with a modestly sized state.
So this leaves me unsure how much data I can store. I will generally be storing a couple of arrays with a few hundred items each of objects made up of strings, ints and dates. If there is a better way to store state between runs then alternatives are welcome, but I do like using these entity functions so I am hoping it is a viable and reliable option.
Update 2-december:
I have been testing storing lists of objects with an 100 item array of objects (strings, int, datetime).
I am running this locally on my machine. I might have done something wrong, but occasionally it returns old data I stored previously instead of the latest data stored in the durable entity storage. I am not sure why this is happening. I can get it to happen by storing large amounts of data, but it also happens randomly at other times.
Generated 100 objects SIZE: 6 365 853 bytes Read Time: 250ms Write Time: 215ms
Generated 1000 objects SIZE: 63 658 851 bytes Read Time: 2s 659ms Write Time: 1s 811ms
Generated 10000 objects Write seemed to succeed, but on read got previous 1000 objects
Generated 10 objects Read back 10 objects as expected
Generated 2000 objects Error: still gets 10 objects
Generated 1000 objects Error: still gets 10 objects
Generated 100 objects Error: still gets 10 objects
Generated 1 object Finally got 1 object back as expected
Generated 10 objects Error: still gets 1 object for three runs, but then on fourth run of the function app suddenly gets 10 objects as it should.
This is on my local machine, win10, i7, 32Gb RAM and without debugger in VS2022.