管理与KV店G-WAN缓存 [英] Managing the caching in G-WAN with KV store

查看:231
本文介绍了管理与KV店G-WAN缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发中使用G-万web服务器C的web应用程序,我想用KV存储包括G-万,以存储生成的网页和次数的页面的计数器已被显示。

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.

在KV存储是一个哈希地图,你可以用它来存储复杂的数据,如结构。

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

这就是我用存储的HTML数据和一个整数是计数器:

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;

该网站的服务器使用多个线程和KV商店的线程之间共享。

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

有关更新领域nbDisplays我使用一个原子操作__sync_fetch_and_add(...)
但我不知道什么是更新域HTML这是一个指针的最佳方式。

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.

是更好:


  1. 要使用现有的存储在KV得到当前值,并将它与G-WAN中提供的add()函数添加到KV存储建立一个新的结构(此功能在更换新的旧体制)

  2. 或者更新存储在KV存储结构的直接值?

我不是在多线程环境中编程,我很害怕一些奇怪的行为...

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

推荐答案

kv_add()被记录为一个原子操作。你可以用它来更新你的柜台,但是这比只使用原子操作递增 nbDisplays 计数器的慢而不触及HTML指针(适用的页面的名称不会更改)。

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).

不过,G-万KV存储的功能,不会使这个看起来像一个哈希图。你不能做的那些范围查询与哈希图

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.

这篇关于管理与KV店G-WAN缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆