PlantUML Integrated

PlantUML Integrated

測試 inline code to UML 的效果 uml Bob->Alice : foo Bob<--Alice : foo , 不知如何

bash ls *

Bob->Alice : foo (福)
Bob<--Alice : bar (巴)
(First usecase)
(Another usecase) as (UC2)  
usecase UC3
usecase (Last\nusecase) as UC4
Class01 <-- Class02
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 -- Class10
(*) --> "First Activity"
"First Activity" --> (*)
:Hello world;
:This is defined on
several **lines**;
[First component]
[Another component] as Comp2  
component Comp3
component [Last\ncomponent] as Comp4
object Object01
object Object02
object Object03
object Object04
object Object05
object Object06
object Object07
object Object08

Object01 <-- Object02
Object03 *-- Object04
Object05 o-- "4" Object06
Object07 .. Object08 : some labels
actor actor
agent agent
artifact artifact
boundary boundary
card card
cloud cloud
component component
control control
database database
entity entity
file file
folder folder
frame frame
interface  interface
node node
package package
queue queue
stack stack
rectangle rectangle
storage storage
usecase usecase
[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string

State1 -> State2
State2 --> [*]
robust "Web Browser" as WB
concise "Web User" as WU

@0
WU is Idle
WB is Idle

@100
WU -> WB : URL
WU is Waiting
WB is Processing

@300
WB is Waiting

Update 2018/8/10

今天測試發現圖出不來!? 看了下 log, RAM 吃光了, 呵呵~ VPS 的 1G RAM 真不好用. 把 database 從 mysql 再次換成了 sqlite 看能否解決問題... 不行.

最後, 只有用 swap file + zswap 來解決問題了. 現在 plantuml 運行得妥妥滴!

Update 2018/9/5

發現這頁在載入時, 因為併行的發出請求, 造成 PlantUML 需要長時間進行 rendering, 然後 timeout, diagram 載入失敗~ 改用 nginx reverse proxy + cache 機制, 應該能解決部份問題, 參數如下

location ~ /uml/ {
   proxy_pass              http://plantuml;
   rewrite                 ^/uml(/.*)$ $1 break;
   proxy_redirect          off;
   proxy_set_header        Host                            $http_host;
   proxy_set_header        X-Real-IP                       $remote_addr;
   proxy_set_header        X-Forwarded-Ssl                 on;
   proxy_set_header        X-Forwarded-For                 $proxy_add_x_forwarded_for;
   proxy_set_header        X-Forwarded-Proto               $scheme;
   proxy_cache             uml;
   proxy_cache_valid       200 1d;
   proxy_cache_use_stale   error timeout invalid_header updating http_500 http_502 http_503 http_504;
   proxy_ignore_headers    Cache-Control;
   proxy_read_timeout      240;
   #proxy_cache_bypass     $http_pragma;
}

原本還加上了 proxy_cache_bypass, 後來發現 cache 在用 chrome 的 Empty cache and hard reload 重新載入時會失效, 確認了下 proxy_cache_bypass 的功能, 原來就是字面的意思 - 什麼情況下不使用 cache 的內容, 且確認了 chrome 會發出 pragma: no-cache 的 request header, 所以這行要去掉~

另外, 看了 log, 還有一個影響圖的輸出的原因是 timed out. 需要在 nginx 中指定長一點的 proxy_read_timeout.

記憶體問題, 是出在 PlantUML 是以 Jetty 提供服務的, default 沒有設定 memory 的上限, 所以需要提高 (如果是系統的 RAM 被吃光, 就不是發生 exception 可以解決的事了, Jetty 就會被 linux 的 OOM Killer 幹掉), 可在 /var/lib/jetty/start.d/ext.ini 中 (隨便找了個 ini 加上的) 加上以下兩行

--exec
-Xmx2g

另外, Jetty 的 default thread pull 上限是 200... 根本沒有這個必要, 在 /usr/local/jetty/etc/jetty-threadpool.xml 改成了 2-8

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure id="threadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">

  <!-- =========================================================== -->
  <!-- Configure the Server Thread Pool.                           -->
  <!-- The server holds a common thread pool which is used by      -->
  <!-- default as the executor used by all connectors and servlet  -->
  <!-- dispatches.                                                 -->
  <!--                                                             -->
  <!-- Configuring a fixed thread pool is vital to controlling the -->
  <!-- maximal memory footprint of the server and is a key tuning  -->
  <!-- parameter for tuning.  In an application that rarely blocks -->
  <!-- then maximal threads may be close to the number of 5*CPUs.  -->
  <!-- In an application that frequently blocks, then maximal      -->
  <!-- threads should be set as high as possible given the memory  -->
  <!-- available.                                                  -->
  <!--                                                             -->
  <!-- Consult the javadoc of o.e.j.util.thread.QueuedThreadPool   -->
  <!-- for all configuration that may be set here.                 -->
  <!-- =========================================================== -->
  <Set name="minThreads" type="int"><Property name="jetty.threadPool.minThreads" deprecated="threads.min" default="2"/></Set>
  <Set name="maxThreads" type="int"><Property name="jetty.threadPool.maxThreads" deprecated="threads.max" default="8"/></Set>
  <Set name="reservedThreads" type="int"><Property name="jetty.threadPool.reservedThreads" default="-1"/></Set>
  <Set name="idleTimeout" type="int"><Property name="jetty.threadPool.idleTimeout" deprecated="threads.timeout" default="60000"/></Set>
  <Set name="detailedDump" type="boolean"><Property name="jetty.threadPool.detailedDump" default="false"/></Set>
</Configure>