Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
ef3dfadf
Commit
ef3dfadf
authored
May 05, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor send optimization
parent
c9437270
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
126 additions
and
56 deletions
+126
-56
benchmarks/Distributed.scala
benchmarks/Distributed.scala
+51
-10
benchmarks/application.conf
benchmarks/application.conf
+5
-29
benchmarks/erlang_test.sh
benchmarks/erlang_test.sh
+1
-1
benchmarks/matching.cpp
benchmarks/matching.cpp
+64
-10
src/binary_serializer.cpp
src/binary_serializer.cpp
+3
-3
src/mailman.cpp
src/mailman.cpp
+2
-3
No files found.
benchmarks/Distributed.scala
View file @
ef3dfadf
...
@@ -4,6 +4,7 @@ import Console.println
...
@@ -4,6 +4,7 @@ import Console.println
case
object
Ok
case
object
Ok
case
object
Done
case
object
Done
case
object
OkTimeout
case
class
Error
(
msg
:
String
)
case
class
Error
(
msg
:
String
)
case
class
KickOff
(
value
:
Int
)
case
class
KickOff
(
value
:
Int
)
case
class
Ping
(
value
:
Int
)
case
class
Ping
(
value
:
Int
)
...
@@ -12,6 +13,8 @@ case class AddPong(path: String)
...
@@ -12,6 +13,8 @@ case class AddPong(path: String)
case
object
Hello
case
object
Hello
case
object
Olleh
case
object
Olleh
case
class
PongDidNotRespond
(
pong
:
ActorRef
,
ping
:
ActorRef
)
case
class
RunClient
(
pongs
:
List
[
ActorRef
],
numPings
:
Int
)
case
class
RunClient
(
pongs
:
List
[
ActorRef
],
numPings
:
Int
)
object
global
{
object
global
{
...
@@ -38,20 +41,50 @@ class PingActor(parent: ActorRef, pong: ActorRef) extends Actor {
...
@@ -38,20 +41,50 @@ class PingActor(parent: ActorRef, pong: ActorRef) extends Actor {
class
ServerActor
(
system
:
ActorSystem
)
extends
Actor
{
class
ServerActor
(
system
:
ActorSystem
)
extends
Actor
{
var
pongs
=
List
[
ActorRef
]()
var
pongs
=
List
[
ActorRef
]()
var
pendingPongs
=
List
[
Pair
[
ActorRef
,
ActorRef
]]()
def
receive
=
{
def
receive
=
{
case
Ping
(
value
)
=>
{
case
Ping
(
value
)
=>
{
sender
!
Pong
(
value
)
sender
!
Pong
(
value
)
}
}
case
Olleh
=>
{
pendingPongs
.
find
(
x
=>
x
.
_1
==
sender
)
match
{
case
Some
((
pong
,
ping
))
=>
{
println
(
"added actor "
+
pong
.
path
)
ping
!
Ok
pendingPongs
=
pendingPongs
.
filterNot
(
x
=>
x
.
_1
==
sender
)
pongs
=
pong
::
pongs
}
case
None
=>
{
// operation already timed out
}
}
}
case
PongDidNotRespond
(
pong
,
ping
)
=>
{
pendingPongs
.
find
(
x
=>
x
.
_1
==
sender
)
match
{
case
Some
(
Pair
(
_
,
y
))
=>
{
ping
!
Error
(
pong
+
" did not respond"
)
pendingPongs
=
pendingPongs
.
filterNot
(
x
=>
x
.
_1
==
sender
)
}
case
None
=>
{
// operation already succeeded
}
}
}
case
AddPong
(
path
)
=>
{
case
AddPong
(
path
)
=>
{
//println("add actor " + path)
if
(
pongs
.
exists
((
x
)
=>
x
.
path
==
path
))
{
if
(
pongs
.
exists
((
x
)
=>
x
.
path
==
path
))
{
sender
!
Ok
sender
!
Ok
}
else
{
}
else
{
import
akka.util.duration._
println
(
"try to add actor "
+
path
)
val
pong
=
system
.
actorFor
(
path
)
val
pong
=
system
.
actorFor
(
path
)
// wait at most 5sec. for response
pong
!
Hello
pong
!
Hello
pongs
=
pong
::
pongs
pendingPongs
=
Pair
(
pong
,
sender
)
::
pendingPongs
sender
!
Ok
system
.
scheduler
.
scheduleOnce
(
5
seconds
,
self
,
PongDidNotRespond
(
pong
,
sender
))
//pong ! Hello
//pongs = pong :: pongs
//sender ! Ok
}
}
}
}
case
KickOff
(
value
)
=>
{
case
KickOff
(
value
)
=>
{
...
@@ -62,9 +95,6 @@ class ServerActor(system: ActorSystem) extends Actor {
...
@@ -62,9 +95,6 @@ class ServerActor(system: ActorSystem) extends Actor {
case
Hello
=>
{
case
Hello
=>
{
sender
!
Olleh
sender
!
Olleh
}
}
case
Olleh
=>
{
//println("Olleh from " + sender)
}
}
}
}
}
...
@@ -101,21 +131,31 @@ class ClientActor extends Actor {
...
@@ -101,21 +131,31 @@ class ClientActor extends Actor {
left
=
left
-
1
left
=
left
-
1
}
}
}
}
case
Error
(
what
)
=>
{
println
(
"Error from "
+
sender
+
" => "
+
what
)
global
.
latch
.
countDown
context
.
stop
(
self
)
}
case
OkTimeout
=>
{
println
(
"At least one pong did not reply... left: "
+
left
)
}
}
}
def
receive
=
{
def
receive
=
{
case
RunClient
(
pongs
,
numPings
)
=>
{
case
RunClient
(
pongs
,
numPings
)
=>
{
import
akka.util.duration._
pongs
.
foreach
(
x
=>
pongs
.
foreach
(
y
=>
if
(
x
!=
y
)
{
pongs
.
foreach
(
x
=>
pongs
.
foreach
(
y
=>
if
(
x
!=
y
)
{
x
!
AddPong
(
y
.
path
.
toString
)
x
!
AddPong
(
y
.
path
.
toString
)
}))
}))
system
.
scheduler
.
scheduleOnce
(
10
seconds
,
self
,
OkTimeout
)
left
=
pongs
.
length
*
(
pongs
.
length
-
1
)
left
=
pongs
.
length
*
(
pongs
.
length
-
1
)
become
(
collectOkMessages
(
pongs
,
numPings
))
become
(
collectOkMessages
(
pongs
,
numPings
))
}
}
}
}
}
}
object
d
istributedClientApp
{
object
D
istributedClientApp
{
def
main
(
args
:
Array
[
String
])
=
{
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
val
system
=
ActorSystem
(
"benchmark"
,
ConfigFactory
.
load
.
getConfig
(
"benchmark"
))
val
system
=
ActorSystem
(
"benchmark"
,
ConfigFactory
.
load
.
getConfig
(
"benchmark"
))
...
@@ -137,12 +177,13 @@ object distributedClientApp {
...
@@ -137,12 +177,13 @@ object distributedClientApp {
system
.
actorOf
(
Props
[
ClientActor
])
!
RunClient
(
pongs
,
numPings
)
system
.
actorOf
(
Props
[
ClientActor
])
!
RunClient
(
pongs
,
numPings
)
global
.
latch
.
await
global
.
latch
.
await
system
.
shutdown
System
.
exit
(
0
)
System
.
exit
(
0
)
}
}
}
}
object
d
istributedServerApp
{
object
D
istributedServerApp
{
def
main
(
args
:
Array
[
String
])
=
{
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
val
sysName
=
if
(
args
.
length
>
0
)
args
(
0
)
else
"pongServer"
val
sysName
=
if
(
args
.
length
>
0
)
args
(
0
)
else
"pongServer"
...
...
benchmarks/application.conf
View file @
ef3dfadf
#benchmark {
# include "common"
#
# akka {
# loglevel = ERROR
# remote {
# netty.port = 0
# untrusted-mode = on
# transport = "akka.remote.netty.NettyRemoteTransport"
# }
# }
#}
benchmark
{
akka
{
loglevel
=
ERROR
actor
{
provider
=
"akka.remote.RemoteActorRefProvider"
}
remote
{
netty
{
hostname
=
"127.0.0.1"
port
=
0
}
}
}
}
pongServer
{
pongServer
{
akka
{
akka
{
loglevel
=
ERROR
loglevel
=
ERROR
...
@@ -33,8 +5,12 @@ pongServer {
...
@@ -33,8 +5,12 @@ pongServer {
provider
=
"akka.remote.RemoteActorRefProvider"
provider
=
"akka.remote.RemoteActorRefProvider"
}
}
remote
{
remote
{
untrusted
-
mode
=
on
remote
-
daemon
-
ack
-
timeout
=
300
s
netty
{
netty
{
hostname
=
"127.0.0.1"
backoff
-
timeout
=
0
ms
connection
-
timeout
=
300
s
hostname
=
"mobi10"
port
=
2244
port
=
2244
}
}
}
}
...
...
benchmarks/erlang_test.sh
View file @
ef3dfadf
#!/bin/bash
#!/bin/bash
echo
"erl -noshell -noinput +P 20000000 -sname benchmark -s
$@
-s init stop"
| ./exec.sh
echo
"erl -noshell -noinput +P 20000000 -s
etcookie abc123 -s
name benchmark -s
$@
-s init stop"
| ./exec.sh
benchmarks/matching.cpp
View file @
ef3dfadf
...
@@ -68,21 +68,69 @@ T rd(char const* cstr)
...
@@ -68,21 +68,69 @@ T rd(char const* cstr)
return
result
;
return
result
;
}
}
void
usage
()
{
cerr
<<
"usage: matching (cow_tuple|object_array) {NUM_LOOPS}"
<<
endl
;
exit
(
1
);
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
announce
<
list
<
int
>>
();
announce
<
list
<
int
>>
();
if
(
argc
!=
2
)
if
(
argc
!=
3
)
usage
();
auto
num_loops
=
rd
<
int64_t
>
(
argv
[
2
]);
any_tuple
m1
;
any_tuple
m2
;
any_tuple
m3
;
any_tuple
m4
;
any_tuple
m5
;
any_tuple
m6
;
if
(
strcmp
(
argv
[
1
],
"cow_tuple"
)
==
0
)
{
m1
=
make_cow_tuple
(
atom
(
"msg1"
),
0
);
m2
=
make_cow_tuple
(
atom
(
"msg2"
),
0.0
);
m3
=
make_cow_tuple
(
atom
(
"msg3"
),
list
<
int
>
{
0
});
m4
=
make_cow_tuple
(
atom
(
"msg4"
),
0
,
"0"
);
m5
=
make_cow_tuple
(
atom
(
"msg5"
),
0
,
0
,
0
);
m6
=
make_cow_tuple
(
atom
(
"msg6"
),
0
,
0.0
,
"0"
);
}
else
if
(
strcmp
(
argv
[
1
],
"object_array"
)
==
0
)
{
auto
m1o
=
new
detail
::
object_array
;
m1o
->
push_back
(
object
::
from
(
atom
(
"msg1"
)));
m1o
->
push_back
(
object
::
from
(
0
));
m1
=
any_tuple
{
m1o
};
auto
m2o
=
new
detail
::
object_array
;
m2o
->
push_back
(
object
::
from
(
atom
(
"msg2"
)));
m2o
->
push_back
(
object
::
from
(
0.0
));
m2
=
any_tuple
{
m2o
};
auto
m3o
=
new
detail
::
object_array
;
m3o
->
push_back
(
object
::
from
(
atom
(
"msg3"
)));
m3o
->
push_back
(
object
::
from
(
list
<
int
>
{
0
}));
m3
=
any_tuple
{
m3o
};
auto
m4o
=
new
detail
::
object_array
;
m4o
->
push_back
(
object
::
from
(
atom
(
"msg4"
)));
m4o
->
push_back
(
object
::
from
(
0
));
m4o
->
push_back
(
object
::
from
(
std
::
string
(
"0"
)));
m4
=
any_tuple
{
m4o
};
auto
m5o
=
new
detail
::
object_array
;
m5o
->
push_back
(
object
::
from
(
atom
(
"msg5"
)));
m5o
->
push_back
(
object
::
from
(
0
));
m5o
->
push_back
(
object
::
from
(
0
));
m5o
->
push_back
(
object
::
from
(
0
));
m5
=
any_tuple
{
m5o
};
auto
m6o
=
new
detail
::
object_array
;
m6o
->
push_back
(
object
::
from
(
atom
(
"msg6"
)));
m6o
->
push_back
(
object
::
from
(
0
));
m6o
->
push_back
(
object
::
from
(
0.0
));
m6o
->
push_back
(
object
::
from
(
std
::
string
(
"0"
)));
m6
=
any_tuple
{
m6o
};
}
else
{
{
cerr
<<
"usage: matching {NUM_LOOPS}"
<<
endl
;
usage
();
return
1
;
}
}
auto
num_loops
=
rd
<
int64_t
>
(
argv
[
1
]);
any_tuple
m1
=
make_cow_tuple
(
atom
(
"msg1"
),
0
);
any_tuple
m2
=
make_cow_tuple
(
atom
(
"msg2"
),
0.0
);
any_tuple
m3
=
cppa
::
make_cow_tuple
(
atom
(
"msg3"
),
list
<
int
>
{
0
});
any_tuple
m4
=
make_cow_tuple
(
atom
(
"msg4"
),
0
,
"0"
);
any_tuple
m5
=
make_cow_tuple
(
atom
(
"msg5"
),
0
,
0
,
0
);
any_tuple
m6
=
make_cow_tuple
(
atom
(
"msg6"
),
0
,
0.0
,
"0"
);
int64_t
m1matched
=
0
;
int64_t
m1matched
=
0
;
int64_t
m2matched
=
0
;
int64_t
m2matched
=
0
;
int64_t
m3matched
=
0
;
int64_t
m3matched
=
0
;
...
@@ -107,4 +155,10 @@ int main(int argc, char** argv)
...
@@ -107,4 +155,10 @@ int main(int argc, char** argv)
part_fun
(
m5
);
part_fun
(
m5
);
part_fun
(
m6
);
part_fun
(
m6
);
}
}
assert
(
m1matched
==
num_loops
);
assert
(
m2matched
==
num_loops
);
assert
(
m3matched
==
num_loops
);
assert
(
m4matched
==
num_loops
);
assert
(
m5matched
==
num_loops
);
assert
(
m6matched
==
num_loops
);
}
}
src/binary_serializer.cpp
View file @
ef3dfadf
...
@@ -41,7 +41,7 @@ using std::enable_if;
...
@@ -41,7 +41,7 @@ using std::enable_if;
namespace
{
namespace
{
constexpr
size_t
chunk_size
=
512
;
constexpr
size_t
chunk_size
=
512
;
conste
px
r
size_t
ui32_size
=
sizeof
(
std
::
uint32_t
);
conste
xp
r
size_t
ui32_size
=
sizeof
(
std
::
uint32_t
);
}
// namespace <anonymous>
}
// namespace <anonymous>
...
@@ -224,12 +224,12 @@ char const* binary_serializer::sendable_data()
...
@@ -224,12 +224,12 @@ char const* binary_serializer::sendable_data()
{
{
auto
s
=
static_cast
<
std
::
uint32_t
>
(
size
());
auto
s
=
static_cast
<
std
::
uint32_t
>
(
size
());
memcpy
(
m_begin
,
&
s
,
ui32_size
);
memcpy
(
m_begin
,
&
s
,
ui32_size
);
return
m_begin
()
;
return
m_begin
;
}
}
void
binary_serializer
::
reset
()
void
binary_serializer
::
reset
()
{
{
m_wr_pos
=
m_begin
;
m_wr_pos
=
m_begin
+
ui32_size
;
}
}
}
// namespace cppa
}
// namespace cppa
src/mailman.cpp
View file @
ef3dfadf
...
@@ -71,10 +71,9 @@ void mailman_loop()
...
@@ -71,10 +71,9 @@ void mailman_loop()
try
try
{
{
bs
<<
msg
;
bs
<<
msg
;
auto
size32
=
static_cast
<
std
::
uint32_t
>
(
bs
.
size
());
DEBUG
(
"--> "
<<
to_string
(
msg
));
DEBUG
(
"--> "
<<
to_string
(
msg
));
auto
sent
=
::
send
(
peer_fd
,
bs
.
sendable_data
(),
bs
.
sendable_size
());
auto
sent
=
::
send
(
peer_fd
,
bs
.
sendable_data
(),
bs
.
sendable_size
()
,
0
);
if
(
sent
!=
bs
.
sendable_size
())
if
(
sent
<
0
||
static_cast
<
size_t
>
(
sent
)
!=
bs
.
sendable_size
())
{
{
disconnect_peer
=
true
;
disconnect_peer
=
true
;
DEBUG
(
"too few bytes written"
);
DEBUG
(
"too few bytes written"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment