Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,60 @@
<artifactId>commons-math3</artifactId>
<version>3.1</version>
</dependency>

<!-- sigar API - performance testing -->
<dependency>
<groupId>org.fusesource</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
</dependency>

<!-- javaMelody -->
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-core</artifactId>
<version>1.59.0</version>
</dependency>

<!-- Jetty -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.6.v20151106</version>
</dependency>


<!-- jRobin -->
<dependency>
<groupId>jrobin</groupId>
<artifactId>jrobin</artifactId>
<version>1.4.0</version>
</dependency>

<!-- Koloboke Lib -->
<dependency>
<groupId>com.koloboke</groupId>
<artifactId>koloboke-compile</artifactId>
<version>0.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.koloboke</groupId>
<!-- `jdk6-7` instead of `jdk8` if you use Java 6 or 7 -->
<artifactId>koloboke-impl-common-jdk8</artifactId>
<version>1.0.0</version>
</dependency>

<!-- http://mvnrepository.com/artifact/com.koloboke/koloboke-api-jdk8 -->
<dependency>
<groupId>com.koloboke</groupId>
<artifactId>koloboke-api-jdk8</artifactId>
<version>1.0.0</version>
</dependency>


</dependencies>



</project>
Binary file added sigar-amd64-winnt.dll
Binary file not shown.
Binary file added sigar-x86-winnt.dll
Binary file not shown.
Binary file added sigar-x86-winnt.lib
Binary file not shown.
Binary file added sigar.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions src/main/java/cec/kolobokeCollections/ExtendedMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cec.kolobokeCollections;

import com.koloboke.collect.map.hash.HashObjObjMap;
import com.koloboke.compile.KolobokeMap;

/**
* Created by mateusz on 13.06.2016.
*/
@KolobokeMap
abstract class ExtendedMap<K,V> implements HashObjObjMap<K, V> {
static <K,V> ExtendedMap<K,V> withExpectedSize(int expectedSize) {
return new KolobokeExtendedMap<K,V>(expectedSize);
}
}
17 changes: 17 additions & 0 deletions src/main/java/cec/kolobokeCollections/MyMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cec.kolobokeCollections;

import com.koloboke.compile.KolobokeMap;
import com.koloboke.compile.NullKeyAllowed;

import java.util.Map;

/**
* Created by mateusz on 13.06.2016.
*/
@KolobokeMap
@NullKeyAllowed
abstract class MyMap<K, V> implements Map<K, V> {
public static <K, V> Map<K, V> withExpectedSize(int expectedSize) {
return new KolobokeMyMap<K, V>(expectedSize);
}
}
16 changes: 16 additions & 0 deletions src/main/java/cec/kolobokeCollections/MySet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cec.kolobokeCollections;

import com.koloboke.compile.KolobokeSet;
import com.koloboke.compile.NullKeyAllowed;

import java.util.Set;

/**
* Created by mateusz on 13.06.2016.
*/
@KolobokeSet
abstract class MySet<E> implements Set<E> {
public static <E> Set<E> withExpectedSize(int expectedSize) {
return new KolobokeMySet<E>(expectedSize);
}
}
20 changes: 20 additions & 0 deletions src/main/java/cec/kolobokeCollections/OptimizedMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cec.kolobokeCollections;

import com.koloboke.compile.KolobokeMap;

/**
* Created by mateusz on 13.06.2016.
*/
@KolobokeMap
public abstract class OptimizedMap<K> {

static <K> OptimizedMap<K> withExpectedSize(int expectedSize) {
return new KolobokeOptimizedMap<K>(expectedSize);
}

abstract void justPut(K key, int value);

abstract int getInt(K key);

abstract boolean justRemove(K key);
}
18 changes: 18 additions & 0 deletions src/main/java/cec/kolobokeCollections/StringHashDoubleMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cec.kolobokeCollections;

import com.koloboke.collect.map.hash.HashObjObjMap;
import com.koloboke.compile.KolobokeMap;
import com.koloboke.compile.NullKeyAllowed;

import static javafx.scene.input.KeyCode.H;

/**
* Created by Mateusz Reczkowski on 13.06.2016.
*/
@KolobokeMap
@NullKeyAllowed
abstract class StringHashDoubleMap implements HashObjObjMap<String, ExtendedMap<String,String>> {
static StringHashDoubleMap withExpectedSize(int expectedSize) {
return new KolobokeStringHashDoubleMap(expectedSize);
}
}
78 changes: 78 additions & 0 deletions src/main/java/cec/kolobokeCollections/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cec.kolobokeCollections;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* Created by Mateusz Reczkowski on 12.06.2016.
*/
public class Test {

public static void main(String[] args) {
Map<String, String> map = MyMap.withExpectedSize(10);
map.put("adam","kowalski");
map.put("jan","nowak");
map.put(null,"null");
System.out.println(map.entrySet());

Set<String> set = MySet.withExpectedSize(10);
set.add("kasia");
set.add("mariola");
System.out.println(set.toString());

ExtendedMap<String,String> map2 = ExtendedMap.withExpectedSize(10);
map2.ensureCapacity(10000000);
map2.put("stas","kozlowski");
map2.put("janek","kras");
for (int i = 0; i < 1000; i++) {
map2.put("tomek"+(char)i,"kwiek"+(char)i);
}
map2.shrink();
System.out.println(map2.entrySet());

OptimizedMap<String> map3 = OptimizedMap.withExpectedSize(10);
map3.justPut("apples", 10);
map3.justPut("oranges", 20);
map3.justPut("kiwi",30);
System.out.println(map3.toString());
map3.justRemove("apples");
System.out.println(map3.toString());

StringHashDoubleMap stringHashDoubleMap = StringHashDoubleMap.withExpectedSize(20000);
long a = System.nanoTime();
for (int i = 0; i < 1000; i++) {
stringHashDoubleMap.put("jan"+(char)i,map2);
}
long b = System.nanoTime();
for (int i = 0; i < 1000; i++) {
System.out.println(stringHashDoubleMap.get("jan"+(char)i).get("tomek"+(char)i));
}
long c = b-a;
System.out.println("Time elapsed: ");
System.out.println((double)c / 1000000000.0);

OptimizedMap<Integer> zz = OptimizedMap.withExpectedSize(100000);
long a2 = System.nanoTime();
for (int i = 0; i < 100000; i++) {
zz.justPut(i,i);
}
long b2 = System.nanoTime();
long c2 = b2-a2;

Map<Integer,Integer> zz2 = new HashMap<>();
long a3 = System.nanoTime();
for (int i = 0; i < 100000; i++) {
zz2.put(i,i);
}
long b3 = System.nanoTime();
long c3 = b3-a3;

System.out.println("Time elapsed for optimized map:");
System.out.println((double)c2 / 1000000000.0);
System.out.println("Time elapsed for plain map:");
System.out.println((double)c3 / 1000000000.0);


}
}
56 changes: 56 additions & 0 deletions src/main/java/cec/monitoring/EmbeddedServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cec.monitoring;

import java.util.EnumSet;
import java.util.Map;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;

import net.bull.javamelody.Parameter;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;

/**
* Created by Mateusz Reczkowski on 12.06.2016.
*/
public class EmbeddedServer {
/**
* Start the server with a http port and optional javamelody parameters.
* @param port Http port
* @param parameters Optional javamelody parameters
* @throws Exception e
*/
public static void start(int port, Map<Parameter, String> parameters) throws Exception {
// Init jetty
final Server server = new Server(port);
final ContextHandlerCollection contexts = new ContextHandlerCollection();
final ServletContextHandler context = new ServletContextHandler(contexts, "/",
ServletContextHandler.SESSIONS);

final Filter monitoringFilter = new net.bull.javamelody.MonitoringFilter();
final FilterHolder filterHolder = new FilterHolder(monitoringFilter);
if (parameters != null) {
for (final Map.Entry<Parameter, String> entry : parameters.entrySet()) {
final net.bull.javamelody.Parameter parameter = entry.getKey();
final String value = entry.getValue();
filterHolder.setInitParameter(parameter.getCode(), value);
}
}
context.addFilter(filterHolder, "/*",
EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));

final RequestLogHandler requestLogHandler = new RequestLogHandler();
contexts.addHandler(requestLogHandler);

final HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { contexts });
server.setHandler(handlers);

server.start();
}
}
39 changes: 39 additions & 0 deletions src/main/java/cec/monitoring/Monitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cec.monitoring;

import java.util.HashMap;
import java.util.Map;

import net.bull.javamelody.Parameter;

/**
* Created by Mateusz Reczkowski on 12.06.2016.
*/
public class Monitor {

public static void runMonitoring(String path, double seconds, int port) throws Exception {

//enter localhost:8080 with 'admin' login and 'pwd' password to enter statistics
final Map<Parameter, String> parameters = new HashMap<>();

// you can add basic auth:
parameters.put(Parameter.AUTHORIZED_USERS, "admin:pwd");

// you can change the default storage directory:
parameters.put(Parameter.STORAGE_DIRECTORY, "" + path);

// you can enable hotspots sampling with a period of 1 second:
parameters.put(Parameter.SAMPLING_SECONDS, "" + seconds);

// set the path of the reports:
parameters.put(Parameter.MONITORING_PATH, "/");

// start the embedded http server with javamelody
EmbeddedServer.start(port, parameters);
}

public static void main(String[] args) throws Exception {

runMonitoring("C:\\diagrams",1.0,8080);

}
}
1 change: 1 addition & 0 deletions src/main/java/cec/test/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static void main(String[] args) throws IOException {
// TypeOption.add("r", 0.5)
// );


cec.run();

//print the results
Expand Down
Loading