简体   繁体   English

为什么我的Laravel Memcache需要太长时间来检索数据?

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

I am making an simple larvel application to show memcached use. 我正在制作一个简单的larvel应用程序来显示memcached的用法。 The Os i am using is ubuntu. 我正在使用的Os是ubuntu。 The records in the database are 50k. 数据库中的记录是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. 我成功安装了memcache并在其中保存了数据,但问题是当我从memcache中检索数据时,它花费的时间与数据库的回溯相同。 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. 我也在Windows上安装了memcache,但是在Windows上问题也是如此。

/**
 * 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. memcache的结果应该比数据库检索得更快。

Performance issues with memcached are tough to debug (at least for me). memcached的性能问题很难调试(至少对我而言)。 I would suggest using the user space strace tool to get some insight into what exactly is causing the delay (read? write? something else?) 我建议使用用户空间strace工具来深入了解导致延迟的原因(读取?写入?其他?)

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. 而不是php进程id把根php-fpm进程ID放在那里,看看你得到了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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