Explorar el Código

Add blade framework (#2973)

* Add blade framework

* Update pom.xml

* fix some configuration
王爵nice hace 7 años
padre
commit
63d3b8e014

+ 3 - 0
frameworks/Java/blade/.gitignore

@@ -0,0 +1,3 @@
+.idea
+*.iml
+/target/

+ 32 - 0
frameworks/Java/blade/README.md

@@ -0,0 +1,32 @@
+# Blade Benchmarking Test
+
+This is the Blade portion of a [benchmarking test suite](../) comparing a variety of web development platforms. The test utilizes Blade routes, JSON serialization, Blade-JDBC for ORM.
+
+### Tests
+
+* [Blade Application](src/main/java/hello/Application.java)
+* [Database Model](src/main/java/hello/mode/World.java)
+
+## Infrastructure Software Versions
+
+* [Blade 2.0.3](https://github.com/biezhi/blade)
+* [Java OpenJDK 1.8](http://openjdk.java.net/)
+* [HikariCP 2.7.1](https://github.com/brettwooldridge/HikariCP)
+
+## References
+
+* https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/http/snoop
+
+## Test URLs
+
+### JSON Encoding Test
+
+http://localhost:9000/json 
+
+### Data-Store/Database Mapping Test 
+
+http://localhost:9000/db?queries=5
+
+### Plain Text Test
+
+http://localhost:9000/plaintext

+ 27 - 0
frameworks/Java/blade/benchmark_config.json

@@ -0,0 +1,27 @@
+{
+  "framework": "blade",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "plaintext_url": "/plaintext",
+      "port": 9000,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "MySQL",
+      "framework": "blade",
+      "language": "Java",
+      "flavor": "None",
+      "orm": "Full",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "blade",
+      "notes": "",
+      "versus": "blade"
+    }
+  }]
+}

+ 36 - 0
frameworks/Java/blade/package.xml

@@ -0,0 +1,36 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
+
+    <id>customAssembly</id>
+    <!-- dir -->
+    <formats>
+        <format>dir</format>
+    </formats>
+
+    <includeBaseDirectory>false</includeBaseDirectory>
+
+    <fileSets>
+        <fileSet>
+            <directory>src/main/resources/</directory>
+            <outputDirectory>/resources</outputDirectory>
+        </fileSet>
+    </fileSets>
+
+    <dependencySets>
+        <dependencySet>
+            <outputDirectory>/lib</outputDirectory>
+            <scope>runtime</scope>
+            <excludes>
+                <exclude>${project.groupId}:${project.artifactId}</exclude>
+            </excludes>
+        </dependencySet>
+        <dependencySet>
+            <outputDirectory>/</outputDirectory>
+            <includes>
+                <include>${project.groupId}:${project.artifactId}</include>
+            </includes>
+        </dependencySet>
+    </dependencySets>
+
+</assembly>

+ 118 - 0
frameworks/Java/blade/pom.xml

@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>hello.world</groupId>
+    <artifactId>hello-blade</artifactId>
+    <version>1.0.0-BUILD-SNAPSHOT</version>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
+        <java.version>1.8</java.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.bladejava</groupId>
+            <artifactId>blade-mvc</artifactId>
+            <version>2.0.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-transport-native-epoll</artifactId>
+            <version>4.1.16.Final</version>
+            <classifier>linux-x86_64</classifier>
+        </dependency>
+
+        <dependency>
+            <groupId>com.bladejava</groupId>
+            <artifactId>blade-jdbc</artifactId>
+            <version>0.2.2-beta</version>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.41</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.zaxxer</groupId>
+            <artifactId>HikariCP</artifactId>
+            <version>2.7.1</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/java</directory>
+                <filtering>false</filtering>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </resource>
+        </resources>
+        <extensions>
+            <extension>
+                <groupId>kr.motd.maven</groupId>
+                <artifactId>os-maven-plugin</artifactId>
+                <version>1.5.0.Final</version>
+            </extension>
+        </extensions>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <appendAssemblyId>false</appendAssemblyId>
+                    <descriptors>
+                        <descriptor>package.xml</descriptor>
+                    </descriptors>
+                    <outputDirectory>${project.build.directory}/dist/</outputDirectory>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.4</version>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <mainClass>hello.Application</mainClass>
+                            <classpathPrefix>lib/</classpathPrefix>
+                            <addClasspath>true</addClasspath>
+                        </manifest>
+                        <manifestEntries>
+                            <!-- Add the path to the configuration file under Class-Path -->
+                            <Class-Path>resources/</Class-Path>
+                        </manifestEntries>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 8 - 0
frameworks/Java/blade/setup.sh

@@ -0,0 +1,8 @@
+#!/bin/bash
+
+fw_depends mysql java maven
+
+mvn clean package
+cd target/dist/hello-blade-1.0.0-BUILD-SNAPSHOT
+
+java -Xms2G -Xmx2G -server -XX:+UseNUMA -XX:+UseParallelGC -XX:+AggressiveOpts -jar hello-blade-1.0.0-BUILD-SNAPSHOT.jar &

+ 11 - 0
frameworks/Java/blade/source_code

@@ -0,0 +1,11 @@
+./blade/src
+./blade/src/main
+./blade/src/main/java
+./blade/src/main/java/hello
+./blade/src/main/java/hello/Application.java
+./blade/src/main/java/hello/DbConfig.java
+./blade/src/main/java/hello/model
+./blade/src/main/java/hello/model/Message.java
+./blade/src/main/java/hello/model/World.java
+./blade/src/main/resources
+./blade/src/main/resources/app.properties

+ 51 - 0
frameworks/Java/blade/src/main/java/hello/Application.java

@@ -0,0 +1,51 @@
+package hello;
+
+import com.blade.Blade;
+import hello.model.Message;
+import hello.model.World;
+import io.netty.buffer.Unpooled;
+import io.netty.util.CharsetUtil;
+
+import java.util.Optional;
+import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Blade Application
+ *
+ * @author biezhi
+ * @date 2017/9/22
+ */
+public class Application {
+
+    private static final int    DB_ROWS           = 308;
+    private static final byte[] STATIC_HELLO_TEXT = "Hello, World!".getBytes(CharsetUtil.UTF_8);
+
+    private static int getQueries(Optional<Integer> queryCount) {
+        int count = queryCount.orElse(1);
+        count = count < 1 ? 1 : count;
+        count = count > 500 ? 500 : count;
+        return count;
+    }
+
+    public static void main(String[] args) {
+        Blade.me()
+                .get("/json", (request, response) -> response.json(new Message()))
+                .get("/db", (request, response) -> {
+                    final Random random = ThreadLocalRandom.current();
+                    response.json(new World().find(random.nextInt(DB_ROWS) + 1));
+                })
+                .get("/queries", (request, response) -> {
+                    int           queries = getQueries(request.queryInt("queries"));
+                    final World[] worlds  = new World[queries];
+                    final Random  random  = ThreadLocalRandom.current();
+                    for (int i = 0; i < queries; i++) {
+                        worlds[i] = new World().find(random.nextInt(DB_ROWS) + 1);
+                    }
+                    response.json(worlds);
+                })
+                .get("/plaintext", (request, response) -> response.body(Unpooled.unreleasableBuffer(Unpooled.directBuffer().writeBytes(STATIC_HELLO_TEXT)).duplicate()))
+                .start(Application.class, args);
+    }
+
+}

+ 38 - 0
frameworks/Java/blade/src/main/java/hello/DbConfig.java

@@ -0,0 +1,38 @@
+package hello;
+
+import com.blade.Blade;
+import com.blade.event.BeanProcessor;
+import com.blade.ioc.annotation.Bean;
+import com.blade.jdbc.Base;
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+/**
+ * @author biezhi
+ * @date 2017/9/22
+ */
+@Bean
+public class DbConfig implements BeanProcessor {
+
+    private static final String DB_URL = "jdbc:mysql://TFB-database:3306/hello_world?jdbcCompliantTruncation=false&amp;elideSetAutoCommits=true&amp;useLocalSessionState=true&amp;cachePrepStmts=true&amp;cacheCallableStmts=true&amp;alwaysSendSetIsolation=false&amp;prepStmtCacheSize=4096&amp;cacheServerConfiguration=true&amp;prepStmtCacheSqlLimit=2048&amp;zeroDateTimeBehavior=convertToNull&amp;traceProtocol=false&amp;useUnbufferedInput=false&amp;useReadAheadInput=false&amp;maintainTimeStats=false&amp;useServerPrepStmts&amp;cacheRSMetadata=true&amp;useSSL=false";
+
+    @Override
+    public void processor(Blade blade) {
+
+        try {
+            HikariConfig config = new HikariConfig();
+            config.setJdbcUrl(DB_URL);
+            config.setUsername("benchmarkdbuser");
+            config.setPassword("benchmarkdbpass");
+            config.addDataSourceProperty("cachePrepStmts", "true");
+            config.addDataSourceProperty("prepStmtCacheSize", "250");
+            config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
+
+            HikariDataSource ds = new HikariDataSource(config);
+            Base.open(ds);
+        } catch (Exception e){
+            System.out.println("Connection database fail");
+        }
+
+    }
+}

+ 9 - 0
frameworks/Java/blade/src/main/java/hello/model/Message.java

@@ -0,0 +1,9 @@
+package hello.model;
+
+/**
+ * @author biezhi
+ * @date 2017/9/22
+ */
+public class Message {
+    private String message = "Hello, World!";
+}

+ 18 - 0
frameworks/Java/blade/src/main/java/hello/model/World.java

@@ -0,0 +1,18 @@
+package hello.model;
+
+import com.blade.jdbc.annotation.Table;
+import com.blade.jdbc.core.ActiveRecord;
+
+/**
+ * World model
+ *
+ * @author biezhi
+ * @date 2017/9/22
+ */
+@Table("world")
+public class World extends ActiveRecord {
+
+    private Integer id;
+    private Integer randomNumber;
+
+}

+ 1 - 0
frameworks/Java/blade/src/main/resources/app.properties

@@ -0,0 +1 @@
+com.blade.logger.defaultLogLevel=error