jonswar / perl-chi Goto Github PK
View Code? Open in Web Editor NEWPerl CHI distribution
Perl CHI distribution
Pleas, read problem description here:
http://www.mail-archive.com/[email protected]/msg10924.html
Thanks!
if I've the below code
my $cache = CHI->new( driver => 'FastMmap',
root_dir => '/Users/xyz',
cache_size => '1k'
);
and this is part of a perl cgi script, how do I avoid the creation of cache every time the script is invoked
I want to persist a connection across multiple http post calls
I think the documentation needs a little extra when it describes Logging. It mentions that logging is done through Log::Any, but neglects to mention the category, which is CHI::Driver.
Good day!
I want to prevent storm of 'compute' method if i have CHI & Memcached and if Memcached is not working already during runtime. Now a get & set methods of Memcached's modules don't die if connection is dropped. And i will not know in program code if memcached will die - no die from theirs - no errors in CHI (CHI catches errors from drivers through die from get & set)...
If i use compute method that after if memcached will die i will get a big problems - every time my $code of compute will run again & again -> i will get a snowball effect.
I think better way will introduce new method for cache instance - 'active' - if our driver of cache functions properly (for memcached this status of connect but i didn't find it there now - i will ask the author of Cache::Memcached::Fast & Cache::Memcached to add it) active will return true else false. If this method will be i will be able to check this status inside 'compute' and if status is not active - rise error through die or to return undef.
There is other way may be. To ask an authors of Cache::Memcached* modules to add die from get & set as an option.
What is your opinion?
Thanks
I noticed this error while building CHI with Perl 5.26
and can noticed that t/smoke-Driver-NonMoose.t was randomly failing
Failed test 'CHI::Test::Driver::NonMoose:l1_cache size = 40'
Failed test 'CHI::Test::Driver::NonMoose:l1_cache keys = 2'
rebuilding it fixes the issue for me, I've not investigated the source of the problem
but there could be something wrong there
# Testing CHI 0.60, Perl 5.026000, /usr/local/cpanel/3rdparty/perl/526/bin/perl
t/00-load.t ............................. ok
t/author-03-pod.t ....................... skipped: these tests are for testing by the author
t/author-file-driver.t .................. skipped: these tests are for testing by the author
t/author-no-data-serializer.t ........... skipped: these tests are for testing by the author
t/author-RequiredModules.t .............. skipped: these tests are for testing by the author
t/Bugs.t ................................ ok
t/Config.t .............................. ok
t/Constants.t ........................... ok
t/Driver-Memory.t ....................... ok
t/Driver-RawMemory.t .................... ok
t/GetError.t ............................ ok
t/Initialize.t .......................... ok
t/release-dependent.t ................... skipped: these tests are for release candidate testing
t/Sanity.t .............................. ok
t/SetError.t ............................ ok
t/smoke-Driver-CacheCache.t ............. skipped: one of required modules not installed: Cache::Cache
t/smoke-Driver-FastMmap.t ............... skipped: one of required modules not installed: Cache::FastMmap
t/smoke-Driver-File-DepthZero.t ......... ok
t/smoke-Driver-File.t ................... ok
# 40 is not between 59 and 99
# Failed test 'CHI::Test::Driver::NonMoose:l1_cache size = 40'
# at /home/rpmbuild/rpm-build/BUILD/CHI-0.60/blib/lib/CHI/t/Driver.pm line 1555.
# (in CHI::t::Driver::NonMoose->test_size_awareness_with_subcaches)
# 2 is not between 3 and 5
# Failed test 'CHI::Test::Driver::NonMoose:l1_cache keys = 2'
# at /home/rpmbuild/rpm-build/BUILD/CHI-0.60/blib/lib/CHI/t/Driver.pm line 1557.
# (in CHI::t::Driver::NonMoose->test_size_awareness_with_subcaches)
# Looks like you failed 2 tests of 874.
t/smoke-Driver-NonMoose.t ...............
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/874 subtests
(less 1 skipped subtest: 871 okay)
t/smoke-Driver-Subcache-l1_cache.t ...... ok
t/smoke-Driver-Subcache-mirror_cache.t .. ok
t/smoke-Null.t .......................... ok
t/Subcache.t ............................ ok
t/Subclass.t ............................ ok
t/Util.t ................................ ok
Test Summary Report
-------------------
t/smoke-Driver-NonMoose.t (Wstat: 512 Tests: 874 Failed: 2)
Failed tests: 863-864
Non-zero exit status: 2
Files=26, Tests=5218, 11 wallclock secs ( 0.57 usr 0.06 sys + 8.49 cusr 0.94 csys = 10.06 CPU)
Result: FAIL
Failed 1/26 test programs. 2/5218 subtests failed.
make: *** [test_dynamic] Error 255
error: Bad exit status from /var/tmp/rpm-tmp.5yDawl (%check)
Race condition in discard_to_size():
setup
$cache = CHI->new(
namespace => 'resizeimg',
expires_in => '5 d',
max_size => int(10.01 * 1024*1024), # M
driver => 'File',
depth => 3,
);
and die
in concurency at line 127, when one process working on clean keys from cache in while { }
when second process got keys to clean but got empty list (because the final size is not written to cache store in the first process yet) then enter in else { }
and die in eval
as affirm
(line 129) then at line 138
Assertion (iterator returned undef, cache should be empty) failed!
at /usr/local/lib64/perl5/5.36/Carp/Assert.pm line 341.
Carp::Assert::affirm(CODE(0x55e658a67468), "iterator returned undef, cache should be empty") called at /usr/local/lib64/perl5/5.36/CHI/Driver/Role/IsSizeAware.pm line 129
eval {...} called at /usr/local/lib64/perl5/5.36/CHI/Driver/Role/IsSizeAware.pm line 118
CHI::Driver::Role::IsSizeAware::discard_to_size(CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware=HASH(0x55e658642e58), 8396996) called at /usr/local/lib64/perl5/5.36/CHI/Driver/Role/IsSizeAware.pm line 71
CHI::Driver::Role::IsSizeAware::__ANON__(CODE(0x55e65892d6e0), CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware=HASH(0x55e658642e58), "/var/www/nestormedia/testsite/img/pages/647-s.jpg;f=webp;w=40"..., CHI::CacheObject=ARRAY(0x55e658a66f58)) called at (eval 93) line 1
CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware::__ANON__(CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware=HASH(0x55e658642e58), "/var/www/nestormedia/testsite/img/pages/647-s.jpg;f=webp;w=40"..., CHI::CacheObject=ARRAY(0x55e658a66f58)) called at (eval 95) line 2
Need to remove affirm
at line 127.
I don't think we should ever die outside eval in discard_to_size at line 138
Driver::Memory is tracking usage of keys to fulfill LRU discard policy.
However ->get() method track last used time even for keys that are not known.
Therefore memory consumption for each "missed" hit will grow and is never released.
IMHO LRU policy is applicable (access should be traced) only for keys which are in cache.
Sample code to demonstrate:
#!/usr/bin/perl
use CHI;
my $_cache = CHI->new( driver => 'Memory', max_size => 1024, global => 1);
for (0 .. 100_000_00){
my $key = rand(10000000);
$_cache->get ( $key ); # memory consumption will hit a sky
}
Pull request:
#33
Good day!
Sometimes i very need to setup namespace for CHI cache during runtime not from constructor but from method.
For example i use Dancer for application and one Dancer will have a some sites inside itself. I can use Dancer::Plugin::Cache::CHI but i cannot change a namespace between applications (for separation of sites).
Is it possible to add this feature at near time?
Or if you have not a free time for this please let me know - i can try to add this feature myself. I am interested your plans about this feature
Thanks!
Good day!
Thanks for useful module!
But i need now in some feature, i can make it myself but before i decide to ask you for approving because i want to see it feature in next releases of CHI ;-)
Idea is a following:
I want to make a feature as Unix make command has. It feature is needed as i think. For example multi-page breaking of each page will depend from whole piece of data for all pages. And if i will cache this whole data piece and define compute method for it, i will want to recompute every page cache if this main whole data piece was changed (page's compute $code will only make like splice method for it of whole piece)
For it i want to add a new features to $cache->compute method:
Every key of compute can be used as 'target' like make. target name == $key of compute (for example if $cache->compute has a certain options)
Every target will be like trigger with his timestamp (like empty files of targets in make utility). Targets will be kept in other namespace with same key as compute's $code and they will may be as a flat numbers of time() or Time::HiRes::time() for example.
Every compute's $code can have some dependences ('prerequisite' term of make) - list of targets with their $code's
CHI if does 'compute' method which has a dependences for it (i am thinking about API now) will look in ones and if current object in cache is not expired but its target ($key) older than target(s) of dependence(s) - it will recompute $code and after will refresh target's trigger time. Of cause it should look up dependeces of dependences recursively for it (every time of compute method). But target triggers will be very small and i think it will not decrease performance dramatically - especially if this behavior will be optionally through certain options of compute method. I know about expire_if option of get but like implementation of this idea for it very cumbersome.
Please tell me your opinion of this
Thanks!
// Perlover :-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.