简体   繁体   中英

Why is my Laravel Memcache taking too long to retrieve data?

I am making an simple larvel application to show memcached use. The Os i am using is ubuntu. The records in the database are 50k.

I successfully installed memcache and saved data in it but the problem is that when i am retrieving data from memcache its taking too long same as a retrival from database would. Kindly let me know what is the issue. I have installed memcache on windows as well but the issue is same on windows as well.

/**
 * Created by PhpStorm.
 * User: Delll
 * Date: 14-Sep-18
 * Time: 2:44 AM
 */

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class User_controller extends Controller{


    public function index(){
        $memcache = 'Using memcache';

        $users = Cache::remember("key",6999,function(){
            return DB::table('users')->get();
        });
//        Cache::pull('key');

        $val= Cache::has('key');
        if($val !=null){
            echo "Found ".$val;
        }else{
            echo "Not Found ".$val;
        }

        return view('pages.home',compact('users','memcache'));
    }

    public function remove(){
        $value = Cache::pull('key');
        return $value;
    }


}

The result from memcache should be retrieved faster than database.

Performance issues with memcached are tough to debug (at least for me). I would suggest using the user space strace tool to get some insight into what exactly is causing the delay (read? write? something else?)

here is an example of getting some info:

 strace -p {php_process_id} -k -r -t -i -T -q  -v -y -yy -C -d -o strace_output.log

instead of php process id put there the root php-fpm process id and see what you get.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM