DR-Tarantool

 view release on metacpan or  search on metacpan

st/stress.pl  view on Meta::CPAN

#!/usr/bin/perl

use warnings;
use strict;

use utf8;
use open qw(:std :utf8);

use lib qw(lib ../lib);
use lib qw(blib/lib blib/arch ../blib/lib ../blib/arch);
use lib qw(st);
use Coro;
use DR::Tarantool::StartTest;
use DR::Tarantool;
use Carp;
use File::Spec::Functions 'catfile', 'rel2abs';
use File::Basename 'dirname', 'basename';
use POSIX;
use UUID;
use Scalar::Util;
use FindBin;
use Coro::AnyEvent;
use AnyEvent;
use Encode qw(decode_utf8);
use feature 'state';
use Data::Dumper;
use Getopt::Long;
use Pod::Usage;



our $tarantool;
our $errors = 0;
my $verbose;

sub cfg($) {
    state $cfg;
    state %cache;
    unless ($cfg) {
        my $name = rel2abs catfile $FindBin::Bin, 'stress.cfg';
        die "File $name is not found\n" unless -r $name;
        $cfg = do $name;
        die if $@;
    }
    
    my $path = shift;
    return $cache{$path} if exists $cache{$path};
    my @spath = split /\./, $path;
    my $o = $cfg;
    for (@spath) {
        croak "Path $path is not found in config file" unless exists $o->{ $_ };
        $o = $o->{ $_ };
    }

    return $cache{$path} = $o;
}

sub df($;@) {
    return unless $verbose;
    my ($fmt, @args) = @_;
    $fmt =~ s/\s*$/\n/;

    unshift @args => $$;
    unshift @args => POSIX::strftime '%d/%m %H:%M:%S' => localtime;
    return printf '%s (%s) ' . $fmt, @args;
}

sub uuid() {
    UUID::generate my $uuid;
    $uuid =~ s/./sprintf '%02x', ord $&/ge;
    return $uuid;
}

sub tnt() {
    state (@process, $tnt);

    unless($tnt) {
        if (@process) {
            push @process => $Coro::current;
            Coro::schedule;

        } else {
            push @process => $Coro::current;
            $tnt = coro_tarantool
                    host        => '127.0.0.1',
                    port        => $tarantool->primary_port,
                    spaces => {
                        0 => {
                            name            => 'one_hash',
                            default_type    => 'STR',
                            fields  => [
                                'id',
                                'value',
                            ],
                            indexes => {
                                0 => {
                                    name    => 'id',
                                    fields  => [ 'id' ],
                                }
                            }
                        },
                        1 => {
                            name            => 'one_tree',
                            default_type    => 'STR',
                            fields  => [
                                'id',
                                'value',
                            ],
                            indexes => {
                                0 => {
                                    name    => 'id',
                                    fields  => [ 'id' ],
                                }
                            }
                        },
                        
                        5   => {
                            name            => 'orders',



( run in 1.599 second using v1.01-cache-2.11-cpan-364913b4093 )