Skip to content

Latest commit

 

History

History
206 lines (157 loc) · 9.42 KB

File metadata and controls

206 lines (157 loc) · 9.42 KB

"ข้าแต่พระยาห์เวห์ พระราชกิจของพระองค์มีมากมายเพียงใด! พระองค์ทรงสร้างสิ่งทั้งปวงด้วยพระปัญญา แผ่นดินโลกเต็มไปด้วยสิ่งที่พระองค์ทรงสร้าง" สดุดี 104:24

Language: English | Português (Brasil) | 简体中文 | 繁體中文 | 日本語 | 한국어 | Türkçe | Русский | Tiếng Việt | ไทย | Deutsch | Español

เฟรมเวิร์ก tinystruct

เฟรมเวิร์กที่เรียบง่ายสำหรับการพัฒนา Java แนวคิดเรียบง่าย ออกแบบดีขึ้น ใช้งานง่าย และมีประสิทธิภาพดี

MvnRepository CodeQL

Star History Chart

ข้อกำหนดเบื้องต้น

  • Java Development Kit (JDK) 17 หรือสูงกว่า
  • Maven สำหรับจัดการ dependencies
  • Text editor หรือ IDE เช่น IntelliJ IDEA, Eclipse หรือ VS Code

เริ่มต้นด้วย tinystruct archetype

คุณสามารถใช้ archetype นี้เพื่อสร้างโปรเจกต์ที่ใช้ tinystruct ได้อย่างรวดเร็ว: https://github.com/tinystruct/tinystruct-archetype

การติดตั้งแบบ manual และเริ่มต้นใช้งาน

  • เพิ่ม dependency ใน pom.xml
<dependency>
  <groupId>org.tinystruct</groupId>
  <artifactId>tinystruct</artifactId>
  <version>1.7.27</version>
  <classifier>jar-with-dependencies</classifier> <!-- ไม่บังคับ -->
</dependency>
  • Extend AbstractApplication ใน Java:
package tinystruct.examples;


import org.tinystruct.AbstractApplication;
import org.tinystruct.ApplicationException;
import org.tinystruct.system.annotation.Action;

public class example extends AbstractApplication {

    @Override
    public void init() {
        // TODO Auto-generated method stub
    }

    @Override
    public String version() {
        return "1.0";
    }

    @Action("praise")
    public String praise() {
        return "Praise the Lord!";
    }

    @Action("say")
    public String say() throws ApplicationException {
        if (null != getContext().getAttribute("--words"))
            return getContext().getAttribute("--words").toString();

        throw new ApplicationException("Could not find the parameter <i>words</i>.");
    }

    @Action("say")
    public String say(String words) {
        return words;
    }

    @Action(value = "hello", mode = Mode.HTTP_GET)
    public String helloGet() {
        return "GET";
    }

    @Action(value = "hello", mode = Mode.HTTP_POST)
    public String helloPost() {
        return "POST";
    }

}

Smalltalk: https://github.com/tinystruct/smalltalk

รันในโหมด CLI

$ bin/dispatcher --version

  _/  '         _ _/  _     _ _/
  /  /  /) (/ _)  /  /  (/ (  /  1.7.27
           /
$ bin/dispatcher --help
Usage: bin/dispatcher COMMAND [OPTIONS]
A command line tool for tinystruct framework
Commands: 
        download        Download a resource from other servers
        exec            To execute native command(s)
        generate        POJO object generator
        install         Install a package
        maven-wrapper   Extract Maven Wrapper
        open            Start a default browser to open the specific URL
        say             Output words
        set             Set system property
        sql-execute     Executes the given SQL statement, which may be an INSERT, UPDATE, DELETE, or DDL statement
        sql-query       Executes the given SQL statement, which returns a single ResultSet object
        update          Update for latest version

Options: 
        --allow-remote-access   Allow to be accessed remotely
        --help                  Help command
        --host                  Host name / IP
        --import                Import application
        --logo                  Print logo
        --settings              Print settings
        --version               Print version

Run 'bin/dispatcher COMMAND --help' for more information on a command.
$ bin/dispatcher say/"Praise the Lord"
Praise the Lord
$ bin/dispatcher say --words Hello --import tinystruct.examples.example
Hello

รันใน HTTP server

# bin/dispatcher start --import org.tinystruct.system.HttpServer 

คุณสามารถเข้าถึง URL ต่อไปนี้:

ทดสอบประสิทธิภาพ

$ wrk -t12 -c400 -d30s "http://127.0.0.1:8080/?q=say/Praise the Lord!"

Running 30s test @ http://127.0.0.1:8080/?q=say/Praise the Lord!
12 threads and 400 connections

Thread Stats   Avg      Stdev     Max       +/- Stdev
Latency        17.44ms  33.42ms   377.73ms  88.98%
Req/Sec        7.27k    1.66k     13.55k    69.94%

2604473 requests in 30.02s, 524.09MB read

Requests/sec:  86753.98
Transfer/sec:  17.46MB

การรองรับมากกว่า 86,000 requests ต่อวินาที พร้อมค่า latency เฉลี่ยต่ำประมาณ 17.44ms แสดงว่า endpoint มีประสิทธิภาพสูงภายใต้โหลดหนัก สิ่งนี้แสดงพลังและประสิทธิภาพของ tinystruct framework แต่ไม่ใช่แค่ตัวเลขเท่านั้น ยังเกี่ยวกับ ปรัชญา เบื้องหลังด้วย

อะไรทำให้ tinystruct framework ทันสมัย?

  1. ไม่ต้องมีเมธอด main() แอปพลิเคชันสามารถเริ่มได้โดยตรงผ่านคำสั่ง CLI เช่น bin/dispatcher

  2. ออกแบบรวมกันสำหรับ CLI และ Web tinystruct ให้ความสำคัญกับ CLI และ Web อย่างเท่าเทียม เหมาะกับงาน AI, script automation และแอปพลิเคชันแบบ hybrid

  3. มี HTTP server แบบ lightweight ในตัว ไม่ว่าจะใช้ Netty หรือ Tomcat, tinystruct รวม lifecycle ของ server ไว้ใน framework

  4. แนวคิด configuration ขั้นต่ำ Configuration ถูกจำกัดไว้เฉพาะส่วนจำเป็น ไม่ต้องมี beans, XML หรือ YAML มากเกินไป

  5. Routing ด้วย annotation @Action ให้กลไก routing ที่ชัดเจนและเข้าใจง่าย

  6. สถาปัตยกรรมที่ให้ความสำคัญกับ performance Overhead ต่ำมาก ไม่มี reflection-based bean scanning และไม่มี interceptor ที่ไม่จำเป็น

  7. ให้อิสระกับนักพัฒนาโดยไม่เพิ่มความซับซ้อน tinystruct ช่วยให้นักพัฒนาโฟกัสกับ business logic จริง และออกแบบให้ โปร่งใส, คาดเดาได้, และ ขยายได้


สถาปัตยกรรม

tinystruct-framework-architecture

สัญญาอนุญาต

Licensed under the Apache License, Version 2.0. คุณไม่สามารถใช้ไฟล์นี้ได้ เว้นแต่จะเป็นไปตาม license. สามารถดูสำเนา license ได้ที่:

http://www.apache.org/licenses/LICENSE-2.0

เว้นแต่กฎหมายที่เกี่ยวข้องกำหนดไว้หรือมีข้อตกลงเป็นลายลักษณ์อักษร ซอฟต์แวร์ที่แจกจ่ายภายใต้ license นี้ให้มาแบบ "AS IS" โดยไม่มีการรับประกันหรือเงื่อนไขใด ๆ