Concurrent data structure design

前端 未结 11 628
名媛妹妹
名媛妹妹 2021-01-30 18:44

I am trying to come up with the best data structure for use in a high throughput C++ server. The data structure will be used to store anything from a few to several million obje

11条回答
  •  [愿得一人]
    2021-01-30 19:23

    You have 3 types of tasks:

    1. iteration (slow)
    2. insertion (fast)
    3. deletion (fast)

    If near consistency is good enough then keep track of the # of active iteration tasks.

    If iterations tasks are active and a new insert or deletion tasks comes in queue those tasks for later processing (but you can return the to caller right away)

    As soon as the last iteration if finished process queued inserts and deletes.

    If an iteration request comes in while inserts or deletes are pending then queue it up.

    If an iteration request comes in while there are just iterations running just have it go and iterate.

    You should still write the iteration to be as fast as possible by making a copy of the data you are iterating over and then process that data in the client if the actual data processing takes a lot more time than the iteration itself.

    I would implement the main collection with a hashtable or stl:map might even be fast enough. Insert/Delete requests could be queued in a list.

提交回复
热议问题