Giter Site home page Giter Site logo

happyfish100 / libshmcache Goto Github PK

View Code? Open in Web Editor NEW
440.0 37.0 133.0 536 KB

libshmcache is a local cache in the share memory for multi processes. high performance due to read is lockless. libshmcache is 100+ times faster than a remote interface such as redis.

Makefile 1.72% C 88.49% M4 0.30% PHP 0.81% Java 7.86% Shell 0.82%
shared-memory key-value cache lockless

libshmcache's People

Contributors

denghongcai avatar dependabot[bot] avatar happyfish100 avatar lizhenchun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libshmcache's Issues

install error on alpine

cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o pthread_func.o pthread_func.c  
In file included from pthread_func.h:18:0,
                 from pthread_func.c:24:
common_define.h:54:0: warning: "PTHREAD_MUTEX_ERRORCHECK" redefined
 #define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
 
In file included from pthread_func.h:14:0,
                 from pthread_func.c:24:
/usr/include/pthread.h:39:0: note: this is the location of the previous definition
 #define PTHREAD_MUTEX_ERRORCHECK 2
 
In file included from pthread_func.h:18:0,
                 from pthread_func.c:24:
pthread_func.c: In function 'init_pthread_lock':
common_define.h:54:34: error: 'PTHREAD_MUTEX_ERRORCHECK_NP' undeclared (first use in this function)
 #define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
                                  ^
pthread_func.c:41:4: note: in expansion of macro 'PTHREAD_MUTEX_ERRORCHECK'
    PTHREAD_MUTEX_ERRORCHECK)) != 0)
    ^~~~~~~~~~~~~~~~~~~~~~~~
common_define.h:54:34: note: each undeclared identifier is reported only once for each function it appears in
 #define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
                                  ^
pthread_func.c:41:4: note: in expansion of macro 'PTHREAD_MUTEX_ERRORCHECK'
    PTHREAD_MUTEX_ERRORCHECK)) != 0)
    ^~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:55: pthread_func.o] Error 1

怎样进行流操作?

你好,happyfish100 ! 首先感谢非常感谢你,开源这么好的软件,而且还可以中文交流。
我现在遇到的问题,我有两个进程间的共享数据是流形式的,写进程开始写时不知道会写多少数据,这样需要怎么操作?我看Api 数据是按key值 读写的,那么是不是我这边写一个value buffer, 就需要告诉读进程当前的写的key值,我看默认的max_value_size 是256k,如果写进程是从网络拿数据,value_size一般都会很小 ,这样多进程交流是不是多了点?怎样做才能使通信减少点了?谢谢!

ERROR - file: shmcache.c, line: 397, malloc -312 bytes fail

多进程微秒级超高频读写同一个KEY造成php进程假死(ps进程存在,但是没有任何打印输出,也没有报错,代码里echo,dump都没有输出,只能 kill -9),可能是进程之间锁竞争造成死锁?然后,手动删除了/tmp/shmcache文件,再运行以下代码报错了:

new ShmCache('/etc/libshmcache.conf', ShmCache::SERIALIZER_PHP);

报错:ERROR - file: shmcache.c, line: 397, malloc -312 bytes fail

运行以下命令

shmcache_delete      shmcache_dump        shmcache_get         shmcache_remove_all  shmcache_set         shmcache_stats

均报 ERROR - file: shmcache.c, line: 397, malloc -312 bytes fail

代码问题

在 shm_object_pool.c 的 shm_object_pool_remove() 函数中,如果出现了op->index != op->obj_pool_info->queue.head,在while循环过程中,原本待移除的obj_offset值会被覆盖。在循环开始前只保留了该offset值所处的索引,即op->index,实际上应该保存op->offsets[op->index]再进入循环。
不过我暂时没有测试到不等的情况,也许理解上出现了偏差,请多指教。

macos报错

[2017-01-12 10:46:27] ERROR - file: shm_op_wrapper.c, line: 117, shmget with key 0104a068 fail, errno: 22, error info: Invalid argument
[2017-01-12 10:46:27] ERROR - file: shmcache.c, line: 702, maybe memory related config parameters changed, clear all share memory command: shmcache_remove_all ../conf/libshmcache.conf
PHP Fatal error: Uncaught ShmCacheException: shmcache_init_from_file: ../conf/libshmcache.conf fail in libshmcache/php-shmcache/test.php:7

Feature Request: rapidjson serializer

Hello,

Kudos on your great work!

I was wondering if you had considered implementing a rapidjson parser?

If not, I'd be interested in giving it a try. Please include any feedback/considerations you think could be helpful.

Thank you for your time/contributions,
Jeff

undefined symbol: iniAnnotationFreeValues

最近对libshmcache更新,发现运行时报错,各版本号如下:

Centos 7
libfastcommon: 1.0.43
libshmcache: 1.0.7

按照INSTALL编译没有任何错误,在运行命令行或者PHP时报告错误

比如运行shmcache_get时, 错误信息如下:

shmcache_get: symbol lookup error: /lib/libshmcache.so: undefined symbol: iniAnnotationFreeValues

代码缺陷!

static inline struct shm_hash_entry *shm_get_hentry_ptr(struct shmcache_context *context,
const int64_t offset)
{
···
base = shmopt_get_value_segment(context, conv.segment.index & 0xFF);
···
}

static inline int64_t shm_get_hentry_offset(struct shm_hash_entry *entry)
{
···
conv.segment.index = entry->memory.index.segment | 0x4000;
···
}

为什么段segment index只用了8位,代表段数最多只能是255,设置段地址|0x4000也是看不懂什么操作!

add travis ci?

I want to use this lib on production env. How about add some unit tests and certain gcc/clang version compile test?

特性咨询

1,基于共享内存的缓存目前已经有鸟哥的yac和apcu,实际上稳定性都存在一些问题,这个库和yac/apcu有何区别呢,benchmark可否和yac/apcu进行比较?

2,扩展对于windows是否支持,zts/nts版本是都支持么?

有没有办法遍历缓存的内容那?

我想用这个库作为数据库在本地的一个缓存,定期和数据库进行同步以保持一致。但是不知道有没有什么方法可以遍历当前缓存的内容,从而发现哪些缓存内容需要删除。

Can't build in Alpine docker

Using below dockerfile:

FROM php:7.4.14-fpm-alpine3.12

RUN apk add -U --no-cache autoconf g++ file re2c make libtool musl-dev \
	&& curl -sSLo libfastcommon.tar.gz 'https://github.com/happyfish100/libfastcommon/archive/V1.0.47.tar.gz' \
    && curl -sSLo libshmcache.tar.gz 'https://github.com/happyfish100/libshmcache/archive/V1.0.7.tar.gz' \
    && tar xzf libfastcommon.tar.gz && cd libfastcommon-* && ./make.sh && ./make.sh install && cd .. \
    && tar xzf libshmcache.tar.gz && cd libshmcache-*/src && make && make install \
      # issue in the next step
      && cd tools && make && make install && cd ../.. \
      && cd php-shmcache && phpize && ./configure && make && make install

Gives error:

cc -g -O1 -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -o shmcache_set shmcache_set.c -lfastcommon -lshmcache -lpthread -ldl -I/usr/local/include
/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../lib/libshmcache.so: undefined reference to `fc_strdup'
collect2: error: ld returned 1 exit status
make: *** [Makefile:15: shmcache_set] Error 1

Similar issues elsewhere:

FIFO vs LRU

发现缓存策略是FIFO,有点好奇为什么没有采用LRU, 一般情况下LRU的性能应该比FIFO好一些。

是有什么特别的考虑吗?谢谢!

异常故障恢复

共享内存的写操纵会存在其他问题,不仅仅是锁,比如下面场景比较棘手,会带来数据一致性不可恢复, 不知道作者是否有考虑过下面的场景:

1: shm.lock();
2: ++ shm.value;
3: 其它逻辑
4: shm.unlock();

shm.lock 这个内部出故障或许还能恢复,但是一致性问题不仅仅在于锁问题,而在于锁中间的逻辑问题.
如果进程在执行代码1成功后,执行了代码2,但这个时候挂了(有可能是被人误杀,比如kill,或者被系统
的oom机制强制杀掉,这种非人为的最可怕), 在没执行完代码4之前挂掉,这个时候代码2所做的更改就无法恢复了!

这种进程可能在任意逻辑未知挂掉,这个时候在共享内存里加锁后,操纵了共享内存,但事情没做完,
这基本上不可恢复. 因为锁共享内存而操纵(写)共享内存的代码逻辑会很多, 这种情况基本上所有使用共享
内存的程序可能都崩溃或使用错误的数据 . 这对上线的程序是灾难性的影响.

谢谢贡献

谢谢贡献这么好用的方案,已经用于生产环境,替代了APCU。

特性咨询

是否支持无锁队列缓存,队列元素是不定长的

关于读操作无锁的疑问

你好,我在发现,对于读操作,在shm_ht_get函数中直接将共享内存中的地址保存在value->data中,也就意味着获取value的时候返回的是共享内存地址。
如果对同一个key进行并发读写,会不会出现对同一块内存操作冲突引起数据错误呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.