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
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"rust-analyzer.cargo.workspaceRoot": "${workspaceFolder}/bencher"
"rust-analyzer.cargo.workspaceRoot": "${workspaceFolder}/bencher",
"java.configuration.updateBuildConfiguration": "interactive",
"java.compile.nullAnalysis.mode": "automatic",
"maven.view": "flat"
}
5 changes: 2 additions & 3 deletions bencher/src/demo_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl SpecTarget for Parallel {
async fn call_once(&mut self, cli: Cli) -> Metric {
let arg = Args {
loopTime: 10000000,
parallelIndex: 100,
parallelIndex: 16,
};
let start_call_ms = SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand All @@ -56,7 +56,7 @@ impl SpecTarget for Parallel {
&serde_json::to_value(arg).unwrap(),
)
.await;
println!("output: {:?}", output);
println!("debug output: {:?}", output);
let res: serde_json::Value = serde_json::from_str(&output).unwrap();
let req_arrive_time = res.get("req_arrive_time").unwrap().as_u64().unwrap();
let bf_exec_time = res.get("bf_exec_time").unwrap().as_u64().unwrap();
Expand All @@ -68,7 +68,6 @@ impl SpecTarget for Parallel {
.expect("Time went backwards")
.as_millis() as u64;

println!("debug output: {:?}", output);
println!(
"\ntotal request latency: {}",
receive_resp_time - start_call_ms
Expand Down
187,500 changes: 187,500 additions & 0 deletions bencher/word_count/random_words.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.serverless_lib;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class InitialExecutor {
public static final ExecutorService executor;

static {
executor = Executors.newFixedThreadPool(5);
}
}
107 changes: 107 additions & 0 deletions demos/balance/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?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>test.functions</groupId>
<artifactId>balance</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<serverless-depend>../sofa_demo</serverless-depend>
</properties>

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.4.3</version>
</dependency>
<!--数据库-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.16</version>
</dependency>
<dependency>
<groupId>manage</groupId>
<artifactId>sofa_demo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<mainClass>test.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>test.Application</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
43 changes: 43 additions & 0 deletions demos/balance/src/main/java/test/functions/CreateUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package test.functions;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.google.gson.JsonObject;

import manage.mapper.BalanceMngMapper;
import manage.model.Balance;
import manage.session.SqlSessionFactoryUtil;

public class CreateUser {

public JsonObject call(JsonObject args) {
String userName = args.get("userName").getAsString();
JsonObject result = new JsonObject();

// 使用 try-with-resources 来管理 SqlSession
SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtil.getBalanceDbSessionFactory();
try (SqlSession session = sqlSessionFactory.openSession()) {
BalanceMngMapper balanceMngMapper = session.getMapper(BalanceMngMapper.class);

// 检查用户是否存在
Balance balance = balanceMngMapper.userExists(userName);
if (balance == null) {
// 创建新用户
balanceMngMapper.createUser(userName);
session.commit(); // 提交事务
result.addProperty("success", true);
result.addProperty("message", "User created successfully");
} else {
result.addProperty("success", false);
result.addProperty("message", "User already exists");
}
} catch (Exception e) {
result.addProperty("success", false);
result.addProperty("message", "Operation failed: " + e.getMessage());
}

return result;
}

}
39 changes: 39 additions & 0 deletions demos/balance/src/main/java/test/functions/MinusBalance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package test.functions;

import java.math.BigDecimal;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.google.gson.JsonObject;

import manage.mapper.BalanceMngMapper;
import manage.session.SqlSessionFactoryUtil;

public class MinusBalance {

public JsonObject call(JsonObject args) {
String userName = args.get("userName").getAsString();
BigDecimal amount = args.get("amount").getAsBigDecimal();
JsonObject result = new JsonObject();

// 使用 try-with-resources 来管理 SqlSession
SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtil.getBalanceDbSessionFactory();
try (SqlSession session = sqlSessionFactory.openSession()) {
BalanceMngMapper balanceMngMapper = session.getMapper(BalanceMngMapper.class);

// 执行减余额操作
balanceMngMapper.minusBalance(userName, amount);
session.commit(); // 提交事务

result.addProperty("success", true);
result.addProperty("message", "Balance deducted successfully");
} catch (Exception e) {
result.addProperty("success", false);
result.addProperty("message", "Operation failed: " + e.getMessage());
}

return result;
}

}
38 changes: 38 additions & 0 deletions demos/balance/src/main/java/test/functions/QueryBalance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package test.functions;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.google.gson.JsonObject;

import manage.mapper.BalanceMngMapper;
import manage.model.Balance;
import manage.session.SqlSessionFactoryUtil;

public class QueryBalance {

public JsonObject call(JsonObject args) {
String userName = args.get("username").getAsString();
JsonObject result = new JsonObject();

// 使用 try-with-resources 来管理 SqlSession
SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtil.getBalanceDbSessionFactory();
try (SqlSession session = sqlSessionFactory.openSession()) {
BalanceMngMapper balanceMngMapper = session.getMapper(BalanceMngMapper.class);

// 查询用户余额
Balance balance = balanceMngMapper.queryBalance(userName);
if (balance == null) {
throw new RuntimeException("user name does not exist");
}
result.addProperty("balance", balance.getBalance().toString());
result.addProperty("success", true);
} catch (Exception e) {
result.addProperty("success", false);
result.addProperty("message", "Operation failed: " + e.getMessage());
}

return result;
}

}
15 changes: 13 additions & 2 deletions demos/parallel_composition/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
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>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<groupId>test.functions</groupId>
<artifactId>word_count</artifactId>
<artifactId>parallel_composition</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
Expand All @@ -14,6 +20,12 @@
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

<!-- <dependency>
<groupId>io.serverless_lib</groupId>
<artifactId>serverless-lib-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> -->
</dependencies>

<build>
Expand Down Expand Up @@ -65,5 +77,4 @@
</plugin>
</plugins>
</build>

</project>
28 changes: 28 additions & 0 deletions demos/parallel_composition/src/main/java/test/Alu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package test;

public class Alu {
public double singleAlu(int times) {
int a = (int) (Math.random() * 91 + 10);
int b = (int) (Math.random() * 91 + 10);
double temp = 0;
for (int i = 0; i < 20; i++) {
for (long j = 0; j < times; j++) {
switch ((int)(j % 4)) {
case 0:
temp = a + b;
break;
case 1:
temp = a - b;
break;
case 2:
temp = (long) a * b;
break;
case 3:
temp = a / b;
break;
}
}
}
return temp;
}
}
Loading