I have relatively fast streams of data coming into my program ( 4 streams of approx. 25Hz) I have to store every input and persist it, and upload it later on. The objects themselves are relatively simple, only made strings and doubles.
I'm thinking I'll use a database for storage. I've thought of files before, but I think a db is better. Either way, if you have a suggestion for this, feel free to share it, but its out of the scope of this question.
Now my problem lies here : how to achieve this task properly ?
The fast flow of objects will be stored into a collection (I don't know which yet), for each stream separately, and every once in a while (probably every 500 objects per stream or so), I'll save them in the database.
I'm afraid this will be prone to race conditions, since I'll be writing in the collection while removing objects from it.
Also, I don't think I need the collection to be ordered because the data is time sensitive ; there is a timestamp on each object of each of the data streams. So it does not really matter if I happen to persist data in the "wrong" order, as long as it's saved in the database, removed from the collection, and that the flow is not interrupted.
Basically, this could be a classic FIFO behaviour, but if it's easier not to then I should be fine anyway. Either way, I'm not sure how to achieve it in terms of logic. I've had my fair share of head scratching and I'd rather go prepared.
I don't specifically need copy-paste code, I'm looking for an actual answer with, if possible, an explanation.
- What kind of collection do you recommend ?
- Do I need some kind of asynchronous collection logic?
- Do I need some kind of thread/lock logic ?
- Is there an collection that can be modified on both ends at the same time?
I have no particular guideline in mind, I'm really open to suggestions.
EDIT : Also, it's worth mentioning i'm using C# if someone wants to link something from a documentation.
Thank you all very much for your time, as always, it is greatly appreciated :)