복붙노트

[REDIS] 레디 스는 메모리가 부족하면 어떻게합니까?

REDIS

레디 스는 메모리가 부족하면 어떻게합니까?

이것은 쉬운 질문이 될 수도 있지만 나는 답을 찾는 힘든 시간을 보내고 있어요. 어떻게 레디 스 2.0 핸들은 최대 할당 된 메모리가 부족합니까? 어떻게 제거 또는 메모리에있는 데이터를 보존 할 데이터를 결정합니까?

해결법

  1. ==============================

    1.당신이있는 경우 가상 메모리 기능은 다음 레디 스 메모리가 부족하게되면 디스크에 "그리 자주 사용하는"데이터를 저장하기 시작합니다 (버전 2.0 또는 2.2, 내가 생각하는 새로운) 설정.

    당신이있는 경우 가상 메모리 기능은 다음 레디 스 메모리가 부족하게되면 디스크에 "그리 자주 사용하는"데이터를 저장하기 시작합니다 (버전 2.0 또는 2.2, 내가 생각하는 새로운) 설정.

    레디 스의 가상 메모리를 사용하지 않으면 운영 체제의 가상 메모리 (즉 스왑)까지 익숙해 시작하고, 성능이 엄청나게 떨어질 것처럼 나타납니다.

    이제, 당신은 또한 더 이상 메모리 (기본)를 사용하는 레디 스를 방지하는 maxmemory 매개 변수와 레디 스를 구성 할 수 있습니다.

    maxmemory에 도달했을 때 레디 스의 최신 버전은 다양한 정책을 가지고 :

    당신 만이 설정 만료와 키를 제거하는 정책을 선택하는 경우, 레디 스 프로그램이 단지의 malloc () 작업을 중단 것 같습니다, 메모리가 부족해 다음 때. 즉, 더 많은 데이터를 저장하려고하면 작업이 단지 비참하게 실패입니다.

    추가 정보를 일부 링크 (당신은 그냥 내 말을 안 이후) :

  2. ==============================

    2.redis.conf, 버전 2.8에서

    redis.conf, 버전 2.8에서

    # Don't use more memory than the specified amount of bytes.
    # When the memory limit is reached Redis will try to remove keys
    # according to the eviction policy selected (see maxmemory-policy).
    #
    # If Redis can't remove keys according to the policy, or if the policy is
    # set to 'noeviction', Redis will start to reply with errors to commands
    # that would use more memory, like SET, LPUSH, and so on, and will continue
    # to reply to read-only commands like GET.
    #
    # This option is usually useful when using Redis as an LRU cache, or to set
    # a hard memory limit for an instance (using the 'noeviction' policy).
    #
    # WARNING: If you have slaves attached to an instance with maxmemory on,
    # the size of the output buffers needed to feed the slaves are subtracted
    # from the used memory count, so that network problems / resyncs will
    # not trigger a loop where keys are evicted, and in turn the output
    # buffer of slaves is full with DELs of keys evicted triggering the deletion
    # of more keys, and so forth until the database is completely emptied.
    #
    # In short... if you have slaves attached it is suggested that you set a lower
    # limit for maxmemory so that there is some free RAM on the system for slave
    # output buffers (but this is not needed if the policy is 'noeviction').
    #
    # maxmemory <bytes>
    
    # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    # is reached. You can select among five behaviors:
    #
    # volatile-lru -> remove the key with an expire set using an LRU algorithm
    # allkeys-lru -> remove any key according to the LRU algorithm
    # volatile-random -> remove a random key with an expire set
    # allkeys-random -> remove a random key, any key
    # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    # noeviction -> don't expire at all, just return an error on write operations
    #
    # Note: with any of the above policies, Redis will return an error on write
    #       operations, when there are no suitable keys for eviction.
    #
    #       At the date of writing these commands are: set setnx setex append
    #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
    #       getset mset msetnx exec sort
    #
    # The default is:
    #
    # maxmemory-policy volatile-lru
    
  3. ==============================

    3.나는 긍정적 인 아니에요, 그래서 난 그냥 최근, 레디 스에 대해 읽기 시작했다. 하지만, 내가 도움이 될 수있는 몇 가지 가벼운 음식 건너 않았다.

    나는 긍정적 인 아니에요, 그래서 난 그냥 최근, 레디 스에 대해 읽기 시작했다. 하지만, 내가 도움이 될 수있는 몇 가지 가벼운 음식 건너 않았다.

    여기 http://antirez.com/post/redis-as-LRU-cache.html에서 단편이다 :

    모든 키가 메모리에 적합해야하지만 거의 사용되지 않는 키에 대한 값이 디스크에 할 수있는 또한, 레디 스 2.0은 VM 모드가 있습니다 :

  4. ==============================

    4.업데이트 4.0 레디 스

    업데이트 4.0 레디 스

    127.0.0.1:6379> MEMORY HELP
    1) "MEMORY DOCTOR                        - Outputs memory problems report"
    2) "MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"
    3) "MEMORY STATS                         - Show memory usage details"
    4) "MEMORY PURGE                         - Ask the allocator to release memory"
    5) "MEMORY MALLOC-STATS                  - Show allocator internal stats"
    
    ############################## MEMORY MANAGEMENT ################################
    
    # Set a memory usage limit to the specified amount of bytes.
    # When the memory limit is reached Redis will try to remove keys
    # according to the eviction policy selected (see maxmemory-policy).
    #
    # If Redis can't remove keys according to the policy, or if the policy is
    # set to 'noeviction', Redis will start to reply with errors to commands
    # that would use more memory, like SET, LPUSH, and so on, and will continue
    # to reply to read-only commands like GET.
    #
    # This option is usually useful when using Redis as an LRU or LFU cache, or to
    # set a hard memory limit for an instance (using the 'noeviction' policy).
    #
    # WARNING: If you have slaves attached to an instance with maxmemory on,
    # the size of the output buffers needed to feed the slaves are subtracted
    # from the used memory count, so that network problems / resyncs will
    # not trigger a loop where keys are evicted, and in turn the output
    # buffer of slaves is full with DELs of keys evicted triggering the deletion
    # of more keys, and so forth until the database is completely emptied.
    #
    # In short... if you have slaves attached it is suggested that you set a lower
    # limit for maxmemory so that there is some free RAM on the system for slave
    # output buffers (but this is not needed if the policy is 'noeviction').
    #
    # maxmemory <bytes>
    
    # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    # is reached. You can select among five behaviors:
    #
    # volatile-lru -> Evict using approximated LRU among the keys with an expire set.
    # allkeys-lru -> Evict any key using approximated LRU.
    # volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
    # allkeys-lfu -> Evict any key using approximated LFU.
    # volatile-random -> Remove a random key among the ones with an expire set.
    # allkeys-random -> Remove a random key, any key.
    # volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
    # noeviction -> Don't evict anything, just return an error on write operations.
    #
    # LRU means Least Recently Used
    # LFU means Least Frequently Used
    #
    # Both LRU, LFU and volatile-ttl are implemented using approximated
    # randomized algorithms.
    #
    # Note: with any of the above policies, Redis will return an error on write
    #       operations, when there are no suitable keys for eviction.
    #
    #       At the date of writing these commands are: set setnx setex append
    #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
    #       getset mset msetnx exec sort
    #
    # The default is:
    #
    # maxmemory-policy noeviction
    
    # LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated
    # algorithms (in order to save memory), so you can tune it for speed or
    # accuracy. For default Redis will check five keys and pick the one that was
    # used less recently, you can change the sample size using the following
    # configuration directive.
    #
    # The default of 5 produces good enough results. 10 Approximates very closely
    # true LRU but costs more CPU. 3 is faster but not very accurate.
    #
    # maxmemory-samples 5
    
  5. ==============================

    5.당신은 그것의 구성에 의해 정의 된 최대에 도달 할 때 레디 스 (2.8) 실제로 응답 궁금해하는 경우는 다음과 같습니다 :

    당신은 그것의 구성에 의해 정의 된 최대에 도달 할 때 레디 스 (2.8) 실제로 응답 궁금해하는 경우는 다음과 같습니다 :

    $ redis-cli
    127.0.0.1:6379> GET 5
    "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
    127.0.0.1:6379> SET 5 a
    (error) OOM command not allowed when used memory > 'maxmemory'.
    
  6. ==============================

    6.나는 최근 중단에없는 자유 메모리의 상황과 내 응용 프로그램 그라운드를 경험 (수 있었다 읽기 수없는 기록)을 실행 PHP 스크립트도 (중도 자신의 트랙에서 죽은 중단하고 죽 수동 -9'd해야했다 메모리가) 제공 후.

    나는 최근 중단에없는 자유 메모리의 상황과 내 응용 프로그램 그라운드를 경험 (수 있었다 읽기 수없는 기록)을 실행 PHP 스크립트도 (중도 자신의 트랙에서 죽은 중단하고 죽 수동 -9'd해야했다 메모리가) 제공 후.

    나는 데이터 손실 (또는 데이터 불일치가) 나는 flushdb을했다, 그래서 발생 및 백업에서 복원 한 가정. 수업은 배운? 백업은 당신의 친구입니다.

  7. ==============================

    7.레디 스가 제거되지 않습니다 당신은 레디 스에 넣어 모든 데이터를합니다 (maxmemory 정책 매개 변수가 noeviction로 설정) 기본적으로 memcached를 같은 캐시 아닌, 유일한 예외가 만료 사용에 있습니다.

    레디 스가 제거되지 않습니다 당신은 레디 스에 넣어 모든 데이터를합니다 (maxmemory 정책 매개 변수가 noeviction로 설정) 기본적으로 memcached를 같은 캐시 아닌, 유일한 예외가 만료 사용에 있습니다.

  8. from https://stackoverflow.com/questions/5068518/what-does-redis-do-when-it-runs-out-of-memory by cc-by-sa and MIT license