Managing the caching in G-WAN with KV store

こ雲淡風輕ζ 提交于 2019-12-24 10:22:14

问题


I am currently developing a web app in C using the G-Wan web server and I want to use the KV Store included with G-Wan in order to store the generated web page and a counter on the number of times the page has been displayed.

The KV store is a hash map you can use to store complex data, like structures.

That's what I have used to store the HTML data and an integer which is the counter:

typedef struct
{    
  char* HTML;    
  int nbDisplays;    

} my_data;

The web server is using several threads and the KV store is shared among the threads.

For updating the field nbDisplays I am using an atomic operation __sync_fetch_and_add (...) But I don't know what is the best way to update the field HTML which is a pointer.

Is it better:

  1. to build a new structure using the existing one stored in KV to get the current values and add it to the KV Store with the add() function provided by G-WAN (this function replace the old structure by the new one)
  2. Or to update directly the values of the structure stored in the KV store?

I am not used to program in a multi thread environment and I am scared about some "strange" behaviors...


回答1:


kv_add() is documented as being an atomic operation. You could use it to update your counter but this is slower than just using an atomic operation to increment the nbDisplays counter without touching the HTML pointer (the name of the page does not change).

But G-Wan KV Store's features does not make this look like a hash map. You can't do those range queries with a hash map.



来源:https://stackoverflow.com/questions/12006364/managing-the-caching-in-g-wan-with-kv-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!