# The 'start_ingest' command causes a zope to fill NEO as fast as possible,
# as if fluentd pushed data.
#
# Use sigma > 0 to have oids of variable size inside NEO.
# To know average compression ratio:
#   x=test_scalability_fluentd/ExtensionTemplateItem/portal_components/extension.erp5.ScalabilityFluentd.py
#   $x 10 1
#   0.434851958247
#   2155 - 65536 (99th percentile)
#   $x 8.787 0
#   0.100036621094
#   6556
#
# The 'start_process' command is similar but by growing a ZBigArray object.
# The random data has a compression ratio of 10%.

[buildout]
extends = test-common.cfg
parts += start_ingest start_process

[start-script-common]
recipe = slapos.recipe.template
output = ${buildout:bin-directory}/${:_buildout_section_name_}
inline =
  #!${buildout:executable}
  import argparse, base64, httplib, sys
  parser = argparse.ArgumentParser()
  _ = parser.add_argument
  _('--site-id', default='erp5')
  _('hostport', metavar='host[:port]', help='Zope address')
  _('password', help="'zope' user password")
  options = []
  def option(name, **kw):
    _(name, **kw)
    options.append(name)
  ${:options}
  args = parser.parse_args()
  qs = []
  for k in options:
    v = getattr(args, k)
    if v is not None:
      t = type(v)
      qs.append('%s=%s' % (k if t is str else k + ':' + t.__name__, v))
  c = httplib.HTTPConnection(args.hostport)
  c.putrequest('GET', '/%s/${:script}?%s' % (args.site_id, '&'.join(qs)))
  c.putheader('Authorization',
    'Basic ' + base64.b64encode('zope:'+args.password))
  c.endheaders()

[start_ingest]
<= start-script-common
options =
  option('id', help='Data Stream id')
  option('mu', type=float)
  option('sigma', type=float)
  option('chunks_per_transaction', nargs='?', type=int, help='default: 128 (8 MiB)')
script = ERP5Site_simulateFluentdIngestion

[start_process]
<= start-script-common
options =
  option('id', help='Data Array id')
script = ERP5Site_dummyZBigArrayProcessing
