Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 8db95e7316c499868cd956f95ab7b4e31cada142 @tokuhirom committed Sep 23, 2009
Showing with 88 additions and 0 deletions.
  1. +15 −0 README
  2. +34 −0 echo-coro.pl
  3. +39 −0 echo-ithread.pl
15 README
@@ -0,0 +1,15 @@
+= get manymanythreads & picoev. =
+
+git clone git://github.com/kazuho/manymanythreads.git
+svn co http://svn.coderepos.org/share/lang/c/picoev/trunk
+
+= compile it =
+
+g++ -o echobench -I . testechoclient.c picoev_kqueue.c
+
+= and run =
+
+-a and -c should be same value.
+
+./echobench -p 9090 -a 100 -c 100 -h 127.0.0.1 -n 100000
+
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+use Coro;
+use Coro::Socket;
+use Coro::Semaphore;
+use Getopt::Long;
+
+my $concurrent = 10;
+my $port = 9010;
+GetOptions(
+ 'concurrent=s' => \$concurrent,
+);
+
+print "coro: http://localhost:9010/\n";
+print "concurrency: $concurrent\n";
+my $sock = Coro::Socket->new(LocalHost => 'localhost', LocalPort => $port, Listen => 10, ReuseAddr => 1);
+my $lock = Coro::Semaphore->new();
+my @coros;
+for my $i (1..$concurrent) {
+ print "awake thread $i\n";
+ push @coros, async {
+ while (1) {
+ my $csock = do {
+ my $guard = $lock->guard;
+ $sock->accept;
+ };
+ while (my $line = <$csock>) {
+ print $csock $line;
+ }
+ }
+ };
+}
+$_->join for @coros;
+
@@ -0,0 +1,39 @@
+use strict;
+use warnings;
+use Getopt::Long;
+use threads;
+use threads::shared;
+use IO::Socket::INET;
+
+my $concurrent = 10;
+my $port = 9090;
+GetOptions(
+ 'concurrent=s' => \$concurrent,
+ 'port=i' => \$port,
+);
+my $locker : shared;
+
+my $sock = IO::Socket::INET->new(
+ LocalHost => 'localhost',
+ LocalPort => $port,
+ Listen => 10,
+ ReuseAddr => 1
+) or die $!;
+my @threads;
+for my $i (1..$concurrent) {
+ push @threads, threads->create(sub {
+ while (1) {
+ my $csock = do {
+ lock($locker);
+ $sock->accept;
+ };
+ while (my $line = <$csock>) {
+ print $csock $line;
+ }
+ }
+ });
+}
+print "ithread: http://localhost:$port/\n";
+print "concurrency: $concurrent\n";
+$_->join for @threads;
+

0 comments on commit 8db95e7

Please sign in to comment.