项目介绍:simpletex-webapi

一个借用SimpleTex解决在线Tex文档识别的方案

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

2024年3月30日星期六

处理机调度的一些名词

 周转时间

◼ 作业的周转时间是指从作业提交到作业完成之间的时间间隔。周转时间是所有时间段之和,包括等待进入内存、在就绪队列中等待、在CPU上执行和I/O执行的时间。这段时间间隔包括了,作业等待、挂起等。

◼ Ti= Tei – Tsi

◼ 平均周转时间

◼ 是指多个作业的周转时间的平均值。n个作业的平均

周转时间:

◼ T =(T1+T2+ ... +Tn)/n(Ti为作业i的周转时间)


带权周转时间

◼ 带权周转时间是指作业周转时间与作业实际运行时间的比值,Wi 。

◼ 注意:这里作业实际运行时间是指在CPU中的时间,不包括阻塞、挂起等时间

◼ 平均带权周转时间

◼ 是指多个作业的带权周转时间的平均值。n个作业的平均带权周转时间:

◼ W =(W1+W2+ ... +Wn)/n(Wi为作业i的带权周转时间)


FCFS first come first start, sjf short first, RR时间片轮转

RR中一个时间片未用完一个process就结束,直接下一个

2024年3月26日星期二

[p2]from_nginx_to_pingora

[p2]from_nginx_to_pingora

part2 Pingora Tutorial

https://github.com/cloudflare/pingora

负载均衡

复刻part1的负载均衡配置
这里使用http,其中xxxxxxxxx是我的公网ipv4地址
main.rs

use async_trait::async_trait;
use pingora::prelude::*;
use std::sync::Arc;

pub struct LB(Arc<LoadBalancer<RoundRobin>>);

#[async_trait]
impl ProxyHttp for LB {
    /// For this small example, we don't need context storage
    type CTX = ();
    fn new_ctx(&self) -> () {
        ()
    }

    async fn upstream_peer(&self, _session: &mut Session, _ctx: &mut ()) -> Result<Box<HttpPeer>> {
        let upstream = self
            .0
            .select(b"", 256) // hash doesn't matter for round robin
            .unwrap();

        // println!("upstream peer is: {:upstream?}");

        // Set SNI to one.one.one.one
        let peer = Box::new(HttpPeer::new(
            upstream,
            false,
            "one.one.one.one".to_string(),
        )); // the second argument, false for http, true for https
        Ok(peer)
    }
    async fn upstream_request_filter(
        &self,
        _session: &mut Session,
        upstream_request: &mut RequestHeader,
        _ctx: &mut Self::CTX,
    ) -> Result<()> {
        upstream_request
            .insert_header("Host", "xxxxxxxxxxx")
            .unwrap();
        Ok(())
    }
}

fn main() {
    let mut my_server = Server::new(None).unwrap();
    my_server.bootstrap();

    let upstreams = LoadBalancer::try_from_iter(["127.0.0.1:12777", "127.0.0.1:12778"]).unwrap();

    let mut lb = http_proxy_service(&my_server.configuration, LB(Arc::new(upstreams)));
    lb.add_tcp("0.0.0.0:12803");

    my_server.add_service(lb);
    my_server.run_forever();
}

Then I can access http://xxxxxxx:12803/say to access my assets.

[p1]from_nginx_to_pingora

[p1]from_nginx_to_pingora

part1 Nginx Tutorial

Download and Install Nginx

This part refer document

wget https://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzvf nginx-1.24.0.tar.gz
./configure --without-http_rewrite_module
make
make install

After there procedures, nginx is installed in my ubuntu device successfully.
I can use vi /usr/local/nginx/conf/nginx.conf to modify config file.

Because I have installed apache2 in my machine, so I need to redefined port of nginx
vi /usr/local/nginx/conf/nginx.conf
about line 36-37, change port and server_name
Here, I change my port to 12800, and change server_name to the ipv4 addr of my ECS.
Then, try to start nginx service.

cd /usr/local/nginx/sbin
# Here I add this path to ~/.bashrc additionally, to enable `nginx` command
nginx -s reload 

Now, I can access the web page by typing xxxxxx:12800 in explorer.
Successfully access to nginx index page

File structure of Nginx config file

https://www.runoob.com/w3cnote/nginx-setup-intro.html

About Forward Proxy

This part refet to https://www.cnblogs.com/yanjieli/p/15229907.html and https://blog.csdn.net/sleepIII/article/details/100787646
Extra care config here

    server {
        listen                           8080;
        server_name                      localhost;
        resolver                         114.114.114.114;
        proxy_connect;
        proxy_connect_allow              443 80;
        proxy_connect_connect_timeout    10s;
        proxy_connect_read_timeout       10s;
        proxy_coneect_send_timeout       10s;
        location / {
            proxy_pass $scheme://$http_host$request_uri;
        }
    }

About Reverse Proxy

Firstly, I code a gin service

package main
import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default()
    r.GET("/", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "Hello World",
        })
    })
    // 监听并在指定的IPv4地址和端口上启动服务
    r.Run("0.0.0.0:12777")
}

这里我没有在ECS的安全组配置中开放12777端口,由此测试反向代理可以保护内部服务
Direct test
In ECS

root@iZbp180e9tshiea7ipj3khZ:/home/test/from-nginx-to-pingora/helloworld-server# curl http://127.0.0.1:12777/say
[GIN] 2024/03/25 - 14:08:48 | 200 |      32.016µs |       127.0.0.1 | GET      "/say"
{"message":"Hello World"}

Local windows

PS C:\Users\scarletborder> curl http://47.98.181.160:12777/say                                                                                                                    curl : The remote server returned an error: (502) Bad Gateway.
At line:1 char:1
+ curl http://47.98.181.160:12777/say
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Modify nginx.conf

server {
    listen       12801;
    server_name  xxxxxxxx;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location /say/ {
        proxy_pass http://localhost:12777/say;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

Now I can access by type http://xxxxxxx:12801/say/

I can also modify conf file like this

location /to777/ {
    proxy_pass http://localhost:12777/;
}

In this condition I can access to it by access xxxx:12801/to777/say

跨域问题

例如前端在8080上开放index.html而后端运行在12777端口号上,虽然能成功发送但是脚本无法获得相应主体
现在想都放到12801下实现同域

server{
    listen          12801;
    server_name     xxxxxxx;
    # 配置代理服务器
    location /backend/say/{
        proxy_pass http://localhost:12777/;
    } 

    # 配置前端服务器
    location /web/{
        proxy_pass http://localhost:12800/;
    }

server{
    listen          12800;
    server_name     xxxxxxxx;

    location /{
        root        html;
        index       myindex.html;
    }
}
}

负载均衡

每台slave具有相同的功能,这里用不同的端口号表示在不同服务器上的项目
localhost:12777 and localhost:12778

创建ano_helloworld-server directory,但是会返回hello another world

这里配置文件的路径

  • /http/server
  • /http/upstream
    配置负载均衡conf/nginx.conf
http{
    upstream mybind{
        server localhost:12777 max_fails=1 weight=1 fail_timeout=10s; 
        server localhost:12778 max_fails=1 weight=1 fail_timeout=10s;
        #weight:        权重,设置相同时则是轮询访问,也可以设置不同的权重,则按对应的比例进行访问
        #max_fails:     最大请求失败次数,默认值为1
        #fail_timeout: 请求失败超时时间,在经历了max_fails次失败后,暂停服务的时间。
    }
    server{
        listen 12802;
        server_name xxxx;
        location / {
            # 直接填集群的名称,需要和上文保持一致
            proxy_pass http://mybind; 
        }
    }
}

Then I can access http://xxxxxxx:12802/say to access my assets.

2024年3月17日星期日

[引流]SimpleTex-WebAPI

这是一个学习性质的项目

 SimpleTex-WebAPI是一个GitHub项目,此项目采用GPL-3.0许可证。

旨在将https://simpletex.cn/ai/latex_ocr 提供的web服务转成适合用户调用的http api服务。

他可以将含有数学公式的图片转换为LaTeX代码。它适用于教育领域,帮助学生和研究人员快速将手写或印刷的数学公式转化为可编辑的文本。此API支持不同的识别模式,适合处理各种图片,并提供识别结果和置信度分数。

更多详情请访问GitHub页面