Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MooBench
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kieker
MooBench
Commits
2ecf3c50
Commit
2ecf3c50
authored
10 years ago
by
Jan Waller
Browse files
Options
Downloads
Patches
Plain Diff
Simple addional tcp reader, just counting incoming bytes
parent
3a38ed9e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frameworks/Kieker/src/kieker/tcp/TestExperiment0.java
+106
-0
106 additions, 0 deletions
frameworks/Kieker/src/kieker/tcp/TestExperiment0.java
with
106 additions
and
0 deletions
frameworks/Kieker/src/kieker/tcp/TestExperiment0.java
0 → 100644
+
106
−
0
View file @
2ecf3c50
/***************************************************************************
* Copyright 2014 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package
kieker.tcp
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.ServerSocketChannel
;
import
java.nio.channels.SocketChannel
;
import
java.util.concurrent.ScheduledThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicLong
;
// Command-Line:
// java -javaagent:lib/kieker-1.10-SNAPSHOT_aspectj.jar -Dkieker.monitoring.writer=kieker.monitoring.writer.tcp.TCPWriter -Dkieker.monitoring.writer.tcp.TCPWriter.QueueFullBehavior=1 -jar dist\MooBench.jar --recursiondepth 10 --totalthreads 1 --methodtime 0 --output-filename raw.csv --totalcalls 10000000
/**
* @author Jan Waller
*/
public
final
class
TestExperiment0
{
private
static
final
int
PORT1
=
10133
;
private
static
final
int
PORT2
=
10134
;
final
static
AtomicInteger
counter
=
new
AtomicInteger
(
0
);
final
static
AtomicLong
totalBytes
=
new
AtomicLong
(
0
);
private
TestExperiment0
()
{}
public
static
void
main
(
final
String
[]
args
)
throws
InterruptedException
{
final
ScheduledThreadPoolExecutor
executorService
=
new
ScheduledThreadPoolExecutor
(
1
);
executorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
public
void
run
()
{
final
int
bytes
=
TestExperiment0
.
counter
.
getAndSet
(
0
);
totalBytes
.
addAndGet
(
bytes
);
if
(
bytes
>
(
1024
*
1024
))
{
System
.
out
.
println
(
"MB/s: "
+
(
bytes
/
(
1024
*
1024
)));
}
else
if
(
bytes
>
1024
)
{
System
.
out
.
println
(
"KB/s: "
+
(
bytes
/
1024
));
}
else
{
System
.
out
.
println
(
" B/s: "
+
bytes
);
}
}
},
0
,
1
,
TimeUnit
.
SECONDS
);
final
Thread
thread1
=
new
Thread
(
new
SocketListener
(
PORT1
));
final
Thread
thread2
=
new
Thread
(
new
SocketListener
(
PORT2
));
thread1
.
start
();
thread2
.
start
();
thread1
.
join
();
thread2
.
join
();
executorService
.
shutdown
();
System
.
out
.
println
(
"Total bytes read: "
+
totalBytes
.
get
());
}
}
class
SocketListener
implements
Runnable
{
private
static
final
int
MESSAGE_BUFFER_SIZE
=
65535
;
private
final
int
port
;
public
SocketListener
(
final
int
port
)
{
this
.
port
=
port
;
}
public
void
run
()
{
ServerSocketChannel
serversocket
=
null
;
try
{
serversocket
=
ServerSocketChannel
.
open
();
serversocket
.
socket
().
bind
(
new
InetSocketAddress
(
this
.
port
));
System
.
out
.
println
(
"Connected: "
+
this
.
port
);
final
SocketChannel
socketChannel
=
serversocket
.
accept
();
final
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
MESSAGE_BUFFER_SIZE
);
while
(
socketChannel
.
read
(
buffer
)
!=
-
1
)
{
buffer
.
flip
();
TestExperiment0
.
counter
.
addAndGet
(
buffer
.
remaining
());
buffer
.
clear
();
}
socketChannel
.
close
();
}
catch
(
final
IOException
ex
)
{
System
.
err
.
println
(
"Error while reading: "
+
ex
);
}
finally
{
if
(
null
!=
serversocket
)
{
try
{
serversocket
.
close
();
}
catch
(
final
IOException
e
)
{
System
.
err
.
println
(
"Failed to close TCP connection!"
+
e
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment