Coder Social home page Coder Social logo

Comments (5)

andreazevedo avatar andreazevedo commented on May 3, 2024

Hello @sebest,
Currently we don't have this support in mcrouter. Generally, you would want to try to fail-over using some ordering (e.g. lower latency pools first, or some other heuristic that might apply for your scenario).
If you want to share how is your setup (i.e. how you do sets, deletes, etc), we might be able help you further.
Thank you

from mcrouter.

sebest avatar sebest commented on May 3, 2024

Hello @andreazevedo ,

Thanx for taking the time to answer to me.

I want to achieve something really similar to the replicated pool with the following criteria:
1/ i just need set and get
2/ for the set i want to write on 2 memcache server and only wait for the first successful set
3/ for the get i want the first non-error and try on the second memcache if the first returned a miss
4/ i want to load balance evenly the the number of "get" requests on my two memcache servers

The only criteria that i can't achieve is number 4 as all the "get' go on the first server on the list as he always has the key.

here is my configuration file:
{
"pools": {
"A": {
"servers": ["172.27.132.244:11211","172.27.135.40:11211",]
}
},
"route": {
"type": "OperationSelectorRoute",
"operation_policies": {
"gets": "LatestRoute|Pool|A",
"set": "AllSyncRoute|Pool|A"
}
}
}

thanx

from mcrouter.

alikhtarov avatar alikhtarov commented on May 3, 2024

Actually you can achieve this by composing RandomRoute and MissFailoverRoute under get policy (BTW I noticed you have gets there - is that intentional? gets and get are two different operations).

You probably want to re-write your config as having two different pools. Something like:

{
  "pools": {
    "A": { "servers": ["172.27.132.244:11211"] },
    "B": { "servers": ["172.27.135.40:11211"] }
  },
  "route": {
    "type": "OperationSelectorRoute",
    "operation_policies": {
      "get": {
        // Randomize on every request between two children
        "type": "RandomRoute",
        "children": [
          // First option: send to miss failover, which tries A first, then B
          { "type": "MissFailoverRoute", "children": ["PoolRoute|A", "PoolRoute|B"] },
          // Second option: same, but try B first, then A
          { "type": "MissFailoverRoute", "children": ["PoolRoute|B", "PoolRoute|A"] }
        ]
      },
      "set": { "type": "AllSyncRoute", "children": ["PoolRoute|A", "PoolRoute|B"] }
    }
  }
}

from mcrouter.

sebest avatar sebest commented on May 3, 2024

Thanx @alikhtarov , i understand the logic behind your example.

I really need gets as for some reason the golang memcache library is using gets to do get.

Now i just have to figure out how to generate this kind of configuration file using consul-template as if i have a 3rd server, implementing the "shifting" logic in the list of children may not be easy:
a,b,c
b,c,a
c,a,b

from mcrouter.

pavlo-fb avatar pavlo-fb commented on May 3, 2024

@sebest you can just have a map of pools in a separate file (pools.json) and then use the following config:

Your config, config.json:

{
  "macros": {
    "all-pools": {
      "type": "constDef",
      "result": "@import(pools.json)"
    },

    // list of routes for each pool [ "PoolRoute|A", "PoolRoute|B", ... ]
    "pool-routes": {
      "type": "constDef",
      "result": {
        "type": "foreach",
        "from": "@sort(@keys(%all-pools%))",
        "use": [ "PoolRoute|%item%" ]
      }
    },

    // number of pools for failover: min(number of pools, 3)
    "failover-cnt": {
      "type": "constDef",
      "result": {
        "type": "if",
        "condition": "@less(@size(%pool-routes%), @int(3))",
        "is_true": "@size(%pool-routes%)",
        "is_false": 3
      }
    },

    // at most %failover-cnt% pool routes starting from %shift%
    "shiftedPoolRoutes": {
      "type": "macroDef",
      "params": [ "shift" ],
      "result": {
        "type": "foreach",
        "from": "@range(@int(0), @sub(%failover-cnt%, @int(1)))",
        "use": [
          "@select(%pool-routes%, @mod(@add(%shift%, %item%), @size(%pool-routes%)))"
        ]
      }
    }
  },

  "pools": "%all-pools%",
  "route": {
    "type": "OperationSelectorRoute",
    "operation_policies": {
      "get": {
        // Randomize on every request between children
        "type": "RandomRoute",
        "children": {
          "type": "foreach",
          "from": "@range(@int(0), @sub(@size(%all-pools%), @int(1)))",
          "use": [
            {
              "type": "MissFailoverRoute",
              "children": "@shiftedPoolRoutes(%item%)"
            }
          ]
        }
      },
      "set": { "type": "AllSyncRoute", "children": "%pool-routes%" }
    }
  }
}

Corresponding pools.json:

{
  "A": { "servers": ["172.27.132.244:11211"] },
  "B": { "servers": ["172.27.135.40:11211"] }
}

To get config without macros, one can send get __mcrouter__.preprocessed_config command to mcrouter.

from mcrouter.

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.