seneca-mesh icon indicating copy to clipboard operation
seneca-mesh copied to clipboard

Auto argument

Open blanchma opened this issue 8 years ago • 7 comments

Is not documented the utility of using auto and the effect with other arguments as setting the bases

blanchma avatar Sep 09 '16 19:09 blanchma

Does anyone know what is the purpose of it ? Reading the source code I think that it raises a service for each item on the listen array, but I'm not sure of the advantage of this. In fact, all services try to start on the same port, so they fail. This has been a headache for me until I discovered.

danielo515 avatar Jun 25 '18 10:06 danielo515

It just automatically calls the listen function with the arguments provided. Otherwise you need to do it by yourself.

@danielo515 How are you configuring your listen? If you set the same port on all your services in dev environment it's going to fail, because (most probably) all are running on localhost. If you leave it empty though, mesh is going to run each in a random port.

https://github.com/senecajs/seneca-mesh/blob/master/mesh.js#L185

To make sure, that's how I configure my mesh listen:

    listen: [{
      pins: [ ......... ],
      port: process.env.PORT || 50000 + Math.floor((10000 * Math.random()))
    }]

otaviosoares avatar Jun 25 '18 20:06 otaviosoares

Hello @otaviosoares , The configuration you posted is the fourth ? fifth ? configuration version that I saw that is not documented and works. Seems that any crazy combination except what it is documented works fine.

To be honest, I started using listen as documented, but that ended on a Die Count error as has been reported on other issue. Then I started to make all kind of crazy combinations:

  • Using just pins with an array of jsonic strings at the root of the mesh config
  • Using pin when it is a single string and pins when they are many at the root of the mesh config
  • Using a listen array of one single element where pin is a list of jsonic strings

The only option that does not work is providing a list property containing an array of objects with a single pin per object, and not specifying any port. Just for the shake of trying I'll check it again, to see what happens.

Something very important that is not documented neither is that each listen element is directly passed to seneca.listen, so you can use any option that seneca listen accepts, that could be pretty handy.

danielo515 avatar Jun 26 '18 07:06 danielo515

Hello again,

I just tried again after reading the source code more carefully and I ended with a configuration that works. Here is an example of what I got:

 Mesh options: { listen:
    [ { pin: { role: 'profile', cmd: '*' } },
      { pin: { role: 'profile', cmd: 'probes.get' } },
      { pin: { role: 'profile', cmd: 'campaigns.get' } },
      { pin: { role: 'profile', cmd: 'universes.get' } },
      { pin: { role: 'profile', cmd: 'probes.del' } },
      { pin: { role: 'profile', cmd: 'campaigns.del' } },
      { pin: { role: 'profile', cmd: 'universes.del' } } ],
   auto: true,
   isbase: false,
   port: '0',
   bases: [ '127.0.0.1:39999', '127.0.0.1:39001' ],
   stop: false,
   balance_client: { debug: { client_updates: true } },
   jointime: 2000,
   sneeze:
    { silent: true,
      swim:
       { interval: 1111,
         joinTimeout: 2777,
         pingTimeout: 2444,
         pingReqTimeout: 2333 } },
   discover:
    { rediscover: true,
      custom: { active: true, find: [Function: dnsSeed] },
      multicast: { active: false },
      registry: { active: false } } }

However, with this new configuration the routing options has changed drastically. Before this is what I was getting:

IN  000010: { role: 'mesh', get: 'members' } # s1jz42gyxa22/uv32kn1gn5by get:members,role:mesh get_members_34 undefined
OUT 000010: { list:
   [ { pin: [ 'cmd:test,role:mesh' ],
       port: 59371,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: 'iws4znzlamoc/1529998816867/92301/3.6.0/base0' },
     { pin:
        [ 'cmd:*,role:profile',
          'cmd:probes.get,role:profile',
          'cmd:campaigns.get,role:profile',
          'cmd:universes.get,role:profile',
          'cmd:probes.del,role:profile',
          'cmd:campaigns.del,role:profile',
          'cmd:universes.del,role:profile' ],
       port: 56688,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '6tw2cbl9oece/1529999007058/92523/3.6.0/profiles' } ] }

But now each command is turned into a "host"

IN  000000: { role: 'mesh', get: 'members' } # 68b9m47zl66b/k9a3z18u8wn8 get:members,role:mesh get_members_38 undefined
IN  000001: { role: 'mesh', get: 'members' } # sogsu97hm7ol/k9a3z18u8wn8 get:members,role:mesh get_members_34 undefined
OUT 000001: { list:
   [ { pin: [ 'cmd:test,role:mesh' ],
       port: 58494,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: 'ug5j45ydwpid/1529999093005/92557/3.6.0/base:repl' },
     { pin: [ 'cmd:*,role:profile' ],
       port: 59306,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '9n5lbw9cfz1m/1529999092982/92556/3.6.0/profiles' },
     { pin: [ 'cmd:test,role:mesh' ],
       port: 57211,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: 'fx0iv8srpdtp/1529999092977/92555/3.6.0/base0' },
     { pin: [ 'cmd:probes.get,role:profile' ],
       port: 59648,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '9n5lbw9cfz1m/1529999092982/92556/3.6.0/profiles' },
     { pin: [ 'cmd:campaigns.get,role:profile' ],
       port: 57782,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '9n5lbw9cfz1m/1529999092982/92556/3.6.0/profiles' },
     { pin: [ 'cmd:universes.get,role:profile' ],
       port: 50790,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '9n5lbw9cfz1m/1529999092982/92556/3.6.0/profiles' },
     { pin: [ 'cmd:probes.del,role:profile' ],
       port: 57608,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '9n5lbw9cfz1m/1529999092982/92556/3.6.0/profiles' },
     { pin: [ 'cmd:campaigns.del,role:profile' ],
       port: 51346,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '9n5lbw9cfz1m/1529999092982/92556/3.6.0/profiles' },
     { pin: [ 'cmd:universes.del,role:profile' ],
       port: 50809,
       host: '0.0.0.0',
       type: 'web',
       model: 'consume',
       instance: '9n5lbw9cfz1m/1529999092982/92556/3.6.0/profiles' } ] }

I did not included it, but the answer is duplicated, seems that every base on the mesh is answering hence the duplicated response.

I don't know what is better in terms of routing, but I suppose that it is better to just have one port open per host.

danielo515 avatar Jun 26 '18 07:06 danielo515

@danielo515 Mesh with auto: true calls listen on each object of you listen array.

If you want to have just one port open then just make it

 Mesh options: { listen:
     [ { pins: { role: 'profile', cmd: '*' },
          { role: 'profile', cmd: 'probes.get' },
          { role: 'profile', cmd: 'campaigns.get' },
          { role: 'profile', cmd: 'universes.get' },
          { role: 'profile', cmd: 'probes.del' },
          { role: 'profile', cmd: 'campaigns.del' },
          { role: 'profile', cmd: 'universes.del' }],
   auto: true,
  ...
}

Instead of

 Mesh options: { listen:
    [ { pin: { role: 'profile', cmd: '*' } },
      { pin: { role: 'profile', cmd: 'probes.get' } },
      { pin: { role: 'profile', cmd: 'campaigns.get' } },
      { pin: { role: 'profile', cmd: 'universes.get' } },
      { pin: { role: 'profile', cmd: 'probes.del' } },
      { pin: { role: 'profile', cmd: 'campaigns.del' } },
      { pin: { role: 'profile', cmd: 'universes.del' } } ],
   auto: true,
  ...
}

otaviosoares avatar Jun 26 '18 17:06 otaviosoares

Thank you very much @otaviosoares , I tried that previously and it resulted on a Die Count error, but maybe it was because any other problem.

Sorry for hijacking this thread, which is about documenting the auto param.

danielo515 avatar Jun 28 '18 09:06 danielo515

One more question, If you want to specify different methods (observe, consume...) you need to specify different pines, which will be attached to different ports. There is no other way right ?

danielo515 avatar Jun 30 '18 15:06 danielo515