Coder Social home page Coder Social logo

Comments (26)

atrope avatar atrope commented on May 31, 2024 1

@stamster Great!

Let me know if you need any input/data or anything that i can test here!

Thank you!
Alan

from phalcon.

stamster avatar stamster commented on May 31, 2024 1

I'm sorry I haven't had time to get onto this. I'm still willing and able though - so I'll try to reproduce it ASAP.
I'll bring on my findings for sure :)

from phalcon.

atrope avatar atrope commented on May 31, 2024

No one knows about this problem?

It just happens when using modelsManager or Model::find and derivatives

Thanks
Alan

from phalcon.

stamster avatar stamster commented on May 31, 2024

Hmm, are you sure you've set up two separate memcached daemons? Or you're using the same daemon with multiple ports?
What keys you're using? I believe all default ones.

The thing is, using Libmemcached as an adapter you can set:

  • in client array: Memcached::OPT_PREFIX_KEY => 'orm.' //this is the DOMAIN!
  • in servers array: 'prefix' => 'model_' //actual prefix of the keys

That way you can use the same memcached instance with different keys/domains in order to distinguish across shared apps/services.
That's what I'm using for Models' metadata, regular sessions and shopping cart sessions.

Also check your Opcache. Try disabling it for a test. If all is good with your memcached setup, then it might be that Opcache is the culprit as you have two files with a same variable name - $config.

P.S. You should also take into account modelsMetadata service, and use \Phalcon\Mvc\Model\Metadata\Libmemcached as adapter if you want to override default in memory cache.

from phalcon.

atrope avatar atrope commented on May 31, 2024

Hello @stamster
I'm using Memcached for Sessions + cache db data also.
I've already tried using prefix and only one memcached instance, but in the end it had the same issue of using the key without the prefix sometimes.
I've set a debug so that i know if its using the right port when using website2 and i'm sure it's setting it right.

[root@memcache ~]# ps ax | grep mem
 8262 pts/0    S+     0:00 grep mem
15190 ?        Ssl  2133:32 /usr/local/bin/memcached -d -p 12111 -u memcached -m 65392 -c 200000 -P /var/run/memcached/memcached.pid -l 0.0.0.0 -t 4
15423 ?        Ssl    0:13 /usr/local/bin/memcached -d -p 12112 -u memcached -m 16384 -c 200000 -P /var/run/memcached/memcached.pid -l 0.0.0.0 -t 4

We are not using opcache.

I'm also using:


$di->setShared('modelsMetadata', function () use ($config) {
    $metaData = new Phalcon\Mvc\Model\Metadata\Libmemcached(
    array(
        "servers" => array(
            array(
                'host' => $config->memcache->host,
               'port' => $config->memcache->port,
               'weight' => 1
            ),
        ),
        "client" => array(Memcached::OPT_HASH => Memcached::HASH_MD5),
        "lifetime" => 3600
    )
);
    return $metaData;
});


With 2 distinct memcached instances i don't need to use prefix.

Thanks for your help but can you think in anything else?

Thanks

Alan

from phalcon.

stamster avatar stamster commented on May 31, 2024

Ahh, now I see.
Try with this.
On your both service definitions using (lib)memcached, set this in servers array:
'statsKey' => null //This is MANDATORY to be defined as null or empty string

Restart memcached and your app server.

P.S. why aren't you using Opcache?! Are you sure about that - it should be enabled by default. Only if you wanted to disable it.... but I don't see a reason.

from phalcon.

atrope avatar atrope commented on May 31, 2024

@stamster,
I've modified for this:


$di->setShared('modelsCache', function () use ($config) {
    //Cache data for one day by default
    $frontCache = new \Phalcon\Cache\Frontend\Data(array(
        "lifetime" => 600
    ));
$cache = new Phalcon\Cache\Backend\Libmemcached($frontCache, array(
     'servers' => array(
         array('host' => $config->memcache->host,
               'port' => $config->memcache->port,
               'weight' => 1
           ),
           'statsKey' => null //This is MANDATORY to be defined as null or empty string
     ),
     'client' => array(
         Memcached::OPT_HASH => Memcached::HASH_MD5,
         Memcached::OPT_PREFIX_KEY => $config->memcache->prefix,
     )
 ));

    return $cache;
});

what do you mean by restart my app server?
What does statsKey null should do? because checking in Phalcon docs is written:
Note: statsKey has a negative performance impact

PS: I've double checked in phpinfo and php -i (web and cli) for opcache and also for any entries in our php.ini and found nothing of opcache neither enabled or disabled.

from phalcon.

atrope avatar atrope commented on May 31, 2024

I've went ahead and done that restarted both memcached and the same thing :/

from phalcon.

stamster avatar stamster commented on May 31, 2024

statsKey used to force default _PHCM prefix in previous 2.0.x series of Phalcon, so that's why I'm used to setting it to null just to make sure. Now it should default to empty string, so that does not seem to be culprit in your case after all.

So you don't use Opcache module at all, "good" in this scenario, bad for production.

Take a look at this example:
https://olddocs.phalconphp.com/en/latest/api/Phalcon_Cache_Backend_Libmemcached.html

A prefix that is automatically perpended to the cache keys

Last but not least -
show actual keys stored in Memcached (in your case you need to double this code as you have two memcached instances running:

$m = new \Memcached('testingSrv1');
        if (!count($m->getServerList())) {
$m->addServer('hostname1', 11211, 1);
        }

$keys = $m->getAllKeys();
print_r($keys);

// ########################

$m = new \Memcached('testingSrv2');
        if (!count($m->getServerList())) {
$m->addServer('hostname2', 11211, 1);
        }

$keys = $m->getAllKeys();
print_r($keys);

from phalcon.

atrope avatar atrope commented on May 31, 2024

@stamster
I use phpMemcachedAdmin to check the keys,
They are stored right in both servers (checked it).
The problem is when reading something already stored it failsback to the one that already has a cache of that key (11211 has and 11212 does not, so 11212 ask for the cache and it finds in 11211 and shows it altough it does not have the key).
It also happened the same when used prefix, it ignored the prefix and got the key without prefix because it existed.
This bug is really driving me crazy I've already tried everything in the last 2 months and now i'm almost sure that's a bug and not a misconfig.
I'm almost sure the configuration is correct and should work as planned.

If you have any mor thoughts that we can do to solve this it'd be great to hear!!

Thanks

Alan

from phalcon.

stamster avatar stamster commented on May 31, 2024

I'll try to reproduce such behavior with setup of two memcached instances.

I think of one issue with your conception, but as I'm not sure let's not put it onto table ATM.

from phalcon.

atrope avatar atrope commented on May 31, 2024

@stamster
Hello, were you able to set up this enviroment?

Thanks

Alan

from phalcon.

atrope avatar atrope commented on May 31, 2024

Great! Thanks :)

from phalcon.

atrope avatar atrope commented on May 31, 2024

Hello @stamster,
Do you have any good news regarding this issue? 😺

from phalcon.

atrope avatar atrope commented on May 31, 2024

Hello Guys,
Anyone else has any insight for this issue?

We are depending on this to lauch the new MultiLanguage website :)

If anyone has any inputs it will help!

Thanks

Alan

from phalcon.

atrope avatar atrope commented on May 31, 2024

Another example if I try to:

$var= Model::query()
->columns("XXXXX")
->where("XXX = Y")
->cache(array("key" => "somekey","lifetime" => 200))
->execute();

It brings the results from the key stored in the instance 12111 if i remove the cache line it brings me the result in the right database. Checking in the instance 11212 the key does not exists.

With phpmemcachedadmin everything works as expected and i can write and read from different caches.

Hope this will bring some other insights..

Thanks
Alan

from phalcon.

Nialld avatar Nialld commented on May 31, 2024

i was also having this issue and i believe it is related to persistence_id when creating a libmemcache instance, if undefined, phalcon will automatically create the instance with persistence_id = "phalcon_cache" (or "phalcon-session" when using session adapter) i set "persistent_id" = "" (or define one if you which to use persistence) in config and this seems to fix my issue, you can do this for sessions also

from phalcon.

nevernet avatar nevernet commented on May 31, 2024

@Nialld i dont think it's related to persistence_id , i have two projects with different memcached servers , and with different persistence_id, but still got same issue.

from phalcon.

nevernet avatar nevernet commented on May 31, 2024

@atrope @Nialld do both of you have solutions? :)

from phalcon.

Nialld avatar Nialld commented on May 31, 2024

@nevernet sorry missed your question, can i see your config... i had to set this in both the session cache section and also the general cache section of my config... i have one config for storing session data and one for general data caching, after i set this option the problem stopped happening for me

from phalcon.

niden avatar niden commented on May 31, 2024

@atrope @nevernet @Nialld

I was reading through this and want to ensure that the issue still persists before trying to reproduce it and fix it. Do you guys have a chance to test this with v4?

from phalcon.

nevernet avatar nevernet commented on May 31, 2024

@niden sorry, i am still working on v3. when i have a chance i will review it with v4.

thank you

from phalcon.

niden avatar niden commented on May 31, 2024

@nevernet Not a problem. Take your time

from phalcon.

Nialld avatar Nialld commented on May 31, 2024

@niden ive been porting our app over to v4 and cant get libmemcached session adapter to work at all. I have switched to stream adapter to move on, the data i set in my libmemcached session is not saving. are there know issues with using memcached as an engine for storing session data in V4?

from phalcon.

ruudboon avatar ruudboon commented on May 31, 2024

@Nialld We don't have any reports regarding libmemcached at the moment. Do you have some code and environment info for us to reproduce your issue? Any error messages?

from phalcon.

stale avatar stale commented on May 31, 2024

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalcon.io/post/github-closing-old-issues

from phalcon.

Related Issues (20)

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.