9.编写负载均衡模块|编写judge功能|postman进行调试(C++)

编写负载均衡模块

代码整体结构

oj_control.hpp

// code: #include...
// input: ""
void Judge(const std::string &number, const std::string in_json, std::string *out_json)
{
	// 0. 根据题目编号,直接拿到对应的题目细节
	// 1. in_json进行反序列化,得到题目的id,得到用户提交源代码,input
	// 2. 重新拼接用户代码+测试用例代码,形成新的代码
	// 3. 选择负载最低的主机(差错处理)
	// 4. 然后发起http请求,得到结果
	// 5. 将结果赋值给out_json
}

建立一个配置文件
![[Pasted image 20250225145655.png]]

47.94.228.92:8082
47.94.228.92:8083
47.94.228.92:8084

oj_control.hpp

#pragma once
  
#include <iostream>
#include <string>
#include <vector>
#include <mutex>
#include <cassert>
  
#include "../comm/util.hpp"
#include "../comm/log.hpp"
#include "oj_model.hpp"
#include "oj_view.hpp"
  
namespace ns_control
{
    using namespace std;
    using namespace ns_log;
    using namespace ns_util;
    using namespace ns_model;
    using namespace ns_view;

  
    //提供服务的主机
    class Machine
    {
    public:
        std::string ip;  //编译服务的ip
        int port;        //编译服务的端口
        uint64_t load;   //编译服务的负载
        std::mutex *mtx; //mutex禁止拷贝,使用指针来完成
    public:
        Machine() : ip(""), port(0), load(0), mtx(nullptr)
        {}
        ~Machine()
        {}
    };
  
    const std::string service_machine = "./conf/service_machine.conf";
    //负载均衡模块
    class LoadBlance
    {
    private:
        //可以提供编译服务的所有主机
        // 每一台主机都有自己的下标,充当当前主机的id
        std::vector<Machine> machines;
        //所有在线的主机id
        std::vector<int> online;
        //所有离线的主机id
        std::vector<int> offline;
    public:
        LoadBlance()
        {
            assert(LoadConf());
        }
        ~LoadBlance()
        {}
    public:
        bool LoadConf(const std::string &machine_list)
        {
  
        }
        bool SmartChoice()
        {
  
        }
        void OfflineMachine()
        {

        }
        void OnlineMachine()
        {
        
        }
    };
}
编写负载均衡器代码
#pragma once
  
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <mutex>
#include <cassert>
  
#include "../comm/util.hpp"
#include "../comm/log.hpp"
#include "oj_model.hpp"
#include "oj_view.hpp"
  
namespace ns_control
{
    using namespace std;
    using namespace ns_log;
    using namespace ns_util;
    using namespace ns_model;
    using namespace ns_view;
  
    //提供服务的主机
    class Machine
    {
    public:
        std::string ip;  //编译服务的ip
        int port;        //编译服务的端口
        uint64_t load;   //编译服务的负载
        std::mutex *mtx; //mutex禁止拷贝,使用指针来完成
    public:
        Machine() : ip(""), port(0), load(0), mtx(nullptr)
        {}
        ~Machine()
        {}
  
    public:
        // 提升主机负载
        void IncLoad()
        {
            if (mtx) mtx->lock();
            ++load;
            if (mtx) mtx->unlock();
        }
        // 减少主机负载
        void DecLoad()
        {
            if (mtx) mtx->lock();
            --load;
            if (mtx) mtx->unlock();
        }
        // 获取主机负载,没有太大的意义,只是为了统一接口
        uint64_t Load()
        {
            uint64_t _load = 0;
            if (mtx) mtx->lock();
            _load = load;
            if (mtx) mtx->unlock();
  
            return _load;
        }
    };
  
    const std::string service_machine = "./conf/service_machine.conf";
    //负载均衡模块
    class LoadBlance
    {
    private:
        //可以提供编译服务的所有主机
        // 每一台主机都有自己的下标,充当当前主机的id
        std::vector<Machine> machines;
        //所有在线的主机id
        std::vector<int> online;
        //所有离线的主机id
        std::vector<int> offline;
        // 保证LoadBlance它的数据安全
        std::mutex mtx;
  
    public:
        LoadBlance()
        {
            assert(LoadConf());
            LOG(INFO) << "加载 " << service_machine << " 成功" << "\n";
        }
        ~LoadBlance()
        {}
    public:
        bool LoadConf(const std::string &machine_conf)
        {
            std::ifstream in(machine_conf);
            if (!in.is_open())
            {
                LOG(FATAL) << " 加载: " << machine_conf << " 失败" << "\n";
                return false;
            }
            std::string line;
            while (std::getline(in, line))
            {
                std::vector<std::string> tokens;
                StringUtil::SplitString(line, &tokens, ":");
                if (tokens.size() != 2)
                {
                    LOG(WARNING) << " 切分 " << line << " 失败" << "\n";
                    continue;
                }
                Machine m;
                m.ip = tokens[0];
                m.port = atoi(tokens[1].c_str());
                m.load = 0;
                m.mtx = new std::mutex();
  
                online.push_back(machines.size());
                machines.push_back(m);
            }
  
            in.close();
            return true;
        }
        // id: 输出型参数
        // m : 输出型参数
        bool SmartChoice()
        {
            // 1. 使用选择好的主机(更新该主机的负载)
            // 2. 我们需要可能离线该主机
            mtx.lock();
            // 负载均衡的算法
            // 1. 随机数+hash
            // 2. 轮询+hash
            int online_num = online.size();
            if (online_num == 0)
            {
                mtx.unlock();
                LOG(FATAL) << " 所有的后端编译主机已经离线, 请运维的同事尽快查看" << "\n";
                return false;
            }
            // 通过遍历的方式,找到所有负载最小的机器
            *id = online[0];
            *m = &machines[online[0]];
            uint64_t min_load = machines[online[0]].Load();
            for (int i = 1; i < online_num; i++)
            {
                uint64_t curr_load = machines[online[i]].Load();
                if (min_load > curr_load)
                {
                    min_load = curr_load;
                    *id = online[i];
                    *m = &machines[online[i]];
                }
            }
            mtx.unlock();
            return true;
        }
        void OfflineMachine()
        {
  
        }
        void OnlineMachine()
        {
  
        }
    };
编写judge功能
#pragma once
  
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <mutex>
#include <cassert>
#include <json/json.h>
  
#include "../comm/util.hpp"
#include "../comm/log.hpp"
#include "../comm/httplib.h"
#include "oj_model.hpp"
#include "oj_view.hpp"
  
namespace ns_control
{
    using namespace std;
    using namespace ns_log;
    using namespace ns_util;
    using namespace ns_model;
    using namespace ns_view;
    using namespace httplib;

  
    //提供服务的主机
    class Machine
    {
    public:
        std::string ip;  //编译服务的ip
        int port;        //编译服务的端口
        uint64_t load;   //编译服务的负载
        std::mutex *mtx; //mutex禁止拷贝,使用指针来完成
    public:
        Machine() : ip(""), port(0), load(0), mtx(nullptr)
        {}
        ~Machine()
        {}
  
    public:
        // 提升主机负载
        void IncLoad()
        {
            if (mtx) mtx->lock();
            ++load;
            if (mtx) mtx->unlock();
        }
        // 减少主机负载
        void DecLoad()
        {
            if (mtx) mtx->lock();
            --load;
            if (mtx) mtx->unlock();
        }
        void ResetLoad()
        {
            if(mtx) mtx->lock();
            load = 0;
            if(mtx) mtx->unlock();
        }
        // 获取主机负载,没有太大的意义,只是为了统一接口
        uint64_t Load()
        {
            uint64_t _load = 0;
            if (mtx) mtx->lock();
            _load = load;
            if (mtx) mtx->unlock();
  
            return _load;
        }
    };
  
    const std::string service_machine = "./conf/service_machine.conf";
    //负载均衡模块
    class LoadBlance
    {
    private:
        //可以提供编译服务的所有主机
        // 每一台主机都有自己的下标,充当当前主机的id
        std::vector<Machine> machines;
        //所有在线的主机id
        std::vector<int> online;
        //所有离线的主机id
        std::vector<int> offline;
        // 保证LoadBlance它的数据安全
        std::mutex mtx;
  
    public:
        LoadBlance()
        {
            assert(LoadConf());
            LOG(INFO) << "加载 " << service_machine << " 成功" << "\n";
        }
        ~LoadBlance()
        {}
    public:
        bool LoadConf(const std::string &machine_conf)
        {
            std::ifstream in(machine_conf);
            if (!in.is_open())
            {
                LOG(FATAL) << " 加载: " << machine_conf << " 失败" << "\n";
                return false;
            }
            std::string line;
            while (std::getline(in, line))
            {
                std::vector<std::string> tokens;
                StringUtil::SplitString(line, &tokens, ":");
                if (tokens.size() != 2)
                {
                    LOG(WARNING) << " 切分 " << line << " 失败" << "\n";
                    continue;
                }
                Machine m;
                m.ip = tokens[0];
                m.port = atoi(tokens[1].c_str());
                m.load = 0;
                m.mtx = new std::mutex();
  
                online.push_back(machines.size());
                machines.push_back(m);
            }
  
            in.close();
            return true;
        }
        // id: 输出型参数
        // m : 输出型参数
        bool SmartChoice()
        {
            // 1. 使用选择好的主机(更新该主机的负载)
            // 2. 我们需要可能离线该主机
            mtx.lock();
            // 负载均衡的算法
            // 1. 随机数+hash
            // 2. 轮询+hash
            int online_num = online.size();
            if (online_num == 0)
            {
                mtx.unlock();
                LOG(FATAL) << " 所有的后端编译主机已经离线, 请运维的同事尽快查看" << "\n";
                return false;
            }
            // 通过遍历的方式,找到所有负载最小的机器
            *id = online[0];
            *m = &machines[online[0]];
            uint64_t min_load = machines[online[0]].Load();
            for (int i = 1; i < online_num; i++)
            {
                uint64_t curr_load = machines[online[i]].Load();
                if (min_load > curr_load)
                {
                    min_load = curr_load;
                    *id = online[i];
                    *m = &machines[online[i]];
                }
            }
            mtx.unlock();
            return true;
        }
        void OfflineMachine(int which)
        {
            mtx.lock();
            for(auto iter = online.begin(); iter != online.end(); iter++)
            {
                if(*iter == which)
                {
                    machines[which].ResetLoad();
                    //要离线的主机已经找到啦
                    online.erase(iter);
                    offline.push_back(which);
                    break; //因为break的存在,所有我们暂时不考虑迭代器失效的问题
                }
            }
            mtx.unlock();
        }
        void OnlineMachine()
        {
            //我们统一上线,后面统一解决
            mtx.lock();
            online.insert(online.end(), offline.begin(), offline.end());
            offline.erase(offline.begin(), offline.end());
            mtx.unlock();
  
            LOG(INFO) << "所有的主机有上线啦!" << "\n";
        }
        //for test
        void ShowMachines()
        {
             mtx.lock();
             std::cout << "当前在线主机列表: ";
             for(auto &id : online)
             {
                 std::cout << id << " ";
             }
             std::cout << std::endl;
             std::cout << "当前离线主机列表: ";
             for(auto &id : offline)
             {
                 std::cout << id << " ";
             }
             std::cout << std::endl;
             mtx.unlock();
        }
    };
  
    class Control
    {
    private:
        Model model_; //提供后台数据
        View view_;   //提供网页渲染功能
        LoadBlance load_blance_; //核心负载均衡器
    public:
        Control()
        {}
        ~Control()
        {}
    public:
        //根据题目数据构建网页
        // html: 输出型参数
        bool AllQuestions(string *html)
        {
            bool ret = true;
            vector<struct Question> all;
            if (model_.GetAllQuestions(&all))
            {
                // 获取题目信息成功,将所有的题目数据构建成网页
                view_.AllExpandHtml(all, html);
            }
            else
            {
                *html = "获取题目失败, 形成题目列表失败";
                ret = false;
            }
            return ret;
        }
        bool Question(const string &number, string *html)
        {
            bool ret = true;
            struct Question q;
            if (model_.GetOneQuestion(number, &q))
            {
                // 获取指定题目信息成功,将所有的题目数据构建成网页
                view_.OneExpandHtml(q, html);
            }
            else
            {
                *html = "指定题目: " + number + " 不存在!";
                ret = false;
            }
            return ret;
        }
  
        // code: #include...
        // input: ""
        void Judge(const std::string &number, const std::string in_json, std::string *out_json)
        {
            // LOG(DEBUG) << in_json << " \nnumber:" << number << "\n";
            // 0. 根据题目编号,直接拿到对应的题目细节
            struct Question q;
            model_.GetOneQuestion(number, &q);
  
            // 1. in_json进行反序列化,得到题目的id,得到用户提交源代码,input
            Json::Reader reader;
            Json::Value in_value;
            reader.parse(in_json, in_value);
            std::string code = in_value["code"].asString();
  
            // 2. 重新拼接用户代码+测试用例代码,形成新的代码
            Json::Value compile_value;
            compile_value["input"] = in_value["input"].asString();
            compile_value["code"] = code + "\n" + q.tail;
            compile_value["cpu_limit"] = q.cpu_limit;
            compile_value["mem_limit"] = q.mem_limit;
            Json::FastWriter writer;
            std::string compile_string = writer.write(compile_value);
  
            // 3. 选择负载最低的主机(差错处理)
            // 规则: 一直选择,直到主机可用,否则,就是全部挂掉
            while(true)
            {
                int id = 0;
                Machine *m = nullptr;
                if(!load_blance_.SmartChoice(&id, &m))
                {
                    break;
                }
  
                // 4. 然后发起http请求,得到结果
                Client cli(m->ip, m->port);
                m->IncLoad();
                LOG(INFO) << " 选择主机成功, 主机id: " << id << " 详情: " << m->ip << ":" << m->port << " 当前主机的负载是: " << m->Load() << "\n";
                if(auto res = cli.Post("/compile_and_run", compile_string, "application/json;charset=utf-8"))
                {
                    // 5. 将结果赋值给out_json
                    if(res->status == 200)
                    {
                        *out_json = res->body;
                        m->DecLoad();
                        LOG(INFO) << "请求编译和运行服务成功..." << "\n";
                        break;
                    }
                    m->DecLoad();
                }
                else
                {
                    //请求失败
                    LOG(ERROR) << " 当前请求的主机id: " << id << " 详情: " << m->ip << ":" << m->port << " 可能已经离线"<< "\n";
                    load_blance_.OfflineMachine(id);
                    load_blance_.ShowMachines(); //仅仅是为了用来调试
                }
            }
        }
    };
}

postman综合调试

oj_server.cc

#include <iostream>
#include "../comm/httplib.h"
#include "oj_control.hpp"
  
using namespace httplib;
using namespace ns_control;
  
int main()
{
    //用户请求的服务路由功能
    Server svr;
    Control ctrl;
  
    // 获取所有的题目列表
    svr.Get("/all_questions", [&ctrl](const Request &req, Response &resp){
        //返回一张包含有所有题目的html网页
        std::string html;
        ctrl.AllQuestions(&html);
        //用户看到的是什么呢??网页数据 + 拼上了题目相关的数据
        resp.set_content(html, "text/html; charset=utf-8");
        //resp.set_content("这是所有题目的列表", "text/plain; charset=utf-8");
    });
  
    // 用户要根据题目编号,获取题目的内容
    // /question/100 -> 正则匹配
    // R"()", 原始字符串raw string,保持字符串内容的原貌,不用做相关的转义
    svr.Get(R"(/question/(\d+))", [&ctrl](const Request &req, Response &resp){
        std::string number = req.matches[1];
        std::string html;
        ctrl.Question(number, &html);
        resp.set_content(html, "text/html; charset=utf-8");
        //resp.set_content("这是指定的一道题:" + number, "text/plain; charset=utf-8");
    });
  
    // 用户提交代码,使用我们的判题功能(1. 每道题的测试用例 2. compile_and_run)
    svr.Post(R"(/judge/(\d+))", [&ctrl](const Request &req, Response &resp){
        std::string number = req.matches[1];
        std::string result_json;
        ctrl.Judge(number, req.body, &result_json);
        resp.set_content(result_json, "application/json;charset=utf-8");
        //resp.set_content("指定题目的判题: " + number, "text/plain; charset=utf-8");
    });
    svr.set_base_dir("./wwwroot");
    svr.listen("0.0.0.0", 8080);
    return 0;
}

makefile

oj_server:oj_server.cc
    g++ -o $@ $^ -std=c++11 -lpthread -lctemplate -ljsoncpp
  
.PHONY:clean
clean:
    rm -f oj_server

将oj_server和compile_server都重新编译一下
启动三台服务器,运行8082,8083和8084
![[Pasted image 20250225182432.png]]

再运行oj_server
![[Pasted image 20250225182759.png]]

要给编译模块添加—D条件编译掉测试用例中的头文件incldue
compiler.hpp

#pragma once
  
#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
  
#include "../comm/util.hpp"
#include "../comm/log.hpp"
  
// 只负责进行代码的编译
  
namespace ns_compiler
{
    // 引入路径拼接功能
    using namespace ns_util;
    using namespace ns_log;
  
    class Compiler
    {
    public:
        Compiler()
        {}
        ~Compiler()
        {}
        //返回值:编译成功:true,否则:false
        //输入参数:编译的文件名
        //file_name: 1234
        //1234 -> ./temp/1234.cpp
        //1234 -> ./temp/1234.exe
        //1234 -> ./temp/1234.stderr
        static bool Compile(const std::string &file_name)
        {
            pid_t pid = fork();
            if(pid < 0)
            {
                LOG(ERROR) << "内部错误,创建子进程失败" << "\n";
                return false;
            }
            else if (pid == 0)
            {
                umask(0);
                int _stderr = open(PathUtil::CompilerError(file_name).c_str(), O_CREAT | O_WRONLY, 0644);
                if(_stderr < 0){
                    LOG(WARNING) << "没有成功形成stderr文件" << "\n";
                    exit(1);
                }
                //重定向标准错误到_stderr
                dup2(_stderr, 2);
                //程序替换,并不影响进程的文件描述符表
                //子进程: 调用编译器,完成对代码的编译工作
                //g++ -o target src -std=c++11
                execlp("g++", "g++", "-o", PathUtil::Exe(file_name).c_str(),\
                PathUtil::Src(file_name).c_str(), "-D", "COMPILER_ONLINE","-std=c++11",  nullptr/*不要忘记*/);
                LOG(ERROR) << "启动编译器g++失败,可能是参数错误" << "\n";
                exit(2);
            }
            else{
                waitpid(pid, nullptr, 0);
                //编译是否成功,就看有没有形成对应的可执行程序
                if(FileUtil::IsFileExists(PathUtil::Exe(file_name))){
                    LOG(INFO) << PathUtil::Src(file_name) << " 编译成功!" << "\n";
                    return true;
                }
            }
            LOG(ERROR) << "编译失败,没有形成可执行程序" << "\n";
            return false;
        }
    };
}
postman

![[Pasted image 20250225195050.png]]

输入地址http://47.94.228.92:8080/judge/2

{
    "code" : "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nclass Solution\n{\npublic:\nint Max(const vector<int> &v)\n{\nreturn 0;\n}\n};\n",
    "input" : ""
}

![[Pasted image 20250225200122.png]]

![[Pasted image 20250225200104.png]]

![[Pasted image 20250225200139.png]]

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/978061.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

安装react报错

安装react报错 背景 执行命令npx create-react-app my-app&#xff0c;然后出现报错unable to resolve dependency tree 解决&#xff1a; 出现这个报错是因为依赖包版本出现冲突&#xff0c;查看package.json可以看到react版本是19.0.0&#xff0c;但是testing-library/rea…

CAD实现一键 面域转线(闭合多段线)——CAD c#二次开发

CAD中存在面域&#xff08;region&#xff09;&#xff0c;当用系统自带命令是&#xff0c;生成的是断开的直线Line。 此插件可实现面域转为闭合的多段线&#xff08;Polyline&#xff09;。效果如下&#xff1a; 一次转600个图形 部分代码如下&#xff1a; public class 面…

快速理解Raft分布式共识算法

目录 拜占庭将军问题 Raft算法是干什么的&#xff1f; 一、领导选举&#xff08;选老板&#xff09; 二、日志复制&#xff08;发通知&#xff09; 三、安全性&#xff08;防篡改&#xff09; &#x1f330; 举个真实例子 ✔️ Raft的优势 基础 状态机 节点类型 任期…

Python学习第十七天之PyTorch保姆级安装

PyTorch安装与部署 一、准备工作二、pytorch介绍三、CPU版本pytorch安装1. 创建虚拟环境2. 删除虚拟环境1. 通过环境名称删除2. 通过环境路径删除 3. 配置镜像源4. 安装pytorch1. 首先激活环境变量2. 进入pytorch官网&#xff0c;找到安装指令 5. 验证pytorch是否安装成功 四、…

Para-Lane: 首个真实世界多车道数据集,目的评估自动驾驶系统中的新型视角合成能力。

2025-02-22&#xff0c;阿里巴巴集团菜鸟自动驾驶实验室和百度研究院共同创建了一个名为 Para-Lane 的真实世界多车道数据集。该数据集目的评估自动驾驶系统中的新型视角合成&#xff08;NVS&#xff09;能力&#xff0c;通过提供大量真实世界的数据&#xff0c;弥补了现有合成…

Linux | Ubuntu 与 Windows 双系统安装 / 高频故障 / UEFI 安全引导禁用

注&#xff1a;本文为 “buntu 与 Windows 双系统及高频故障解决” 相关文章合辑。 英文引文&#xff0c;机翻未校。 How to install Ubuntu 20.04 and dual boot alongside Windows 10 如何将 Ubuntu 20.04 和双启动与 Windows 10 一起安装 Dave’s RoboShack Published in…

flutter 专题 八十二 Flutter路由框架Fluro简介

在Flutter应用开发过程中&#xff0c;除了使用Flutter官方提供的路由外&#xff0c;还可以使用一些第三方路由框架来实现页面管理和导航&#xff0c;如Fluro、Frouter等。 Fluro作为一款优秀的Flutter企业级路由框架&#xff0c;Fluro的使用比官方提供的路由框架要复杂一些&…

(十)趣学设计模式 之 外观模式!

目录 一、 啥是外观模式&#xff1f;二、 为什么要用外观模式&#xff1f;三、 外观模式的实现方式四、 外观模式的优缺点五、 外观模式的应用场景六、 总结 &#x1f31f;我的其他文章也讲解的比较有趣&#x1f601;&#xff0c;如果喜欢博主的讲解方式&#xff0c;可以多多支…

为AI聊天工具添加一个知识系统 之124 详细设计之65 人类文化和习俗,即文化上的差异-根本差异 之2

本文要点 要点 “取” 本身 是一个具有 主谓宾 三格的 多“格”词。 三“格”&#xff08;主/谓/宾&#xff09;分别是&#xff1a; 主取&#xff0c;取法&#xff08;能取&#xff1a;两组分别 是 析取取“异”&#xff08;三个“不同”&#xff09;和合取取“同”&#xf…

AXI协议详解及FPGA仿真

AXI协议详解及FPGA仿真 1 摘要 AMBA AXI 协议是以高性能&#xff0c;高频系统设计为目标&#xff0c;提供了很多适合高速亚微型系统互连的特征。为相邻存储器连续进行数据传输提供的一种高频率&#xff0c;高带宽&#xff0c;低延迟的总线协议&#xff0c;是一种突发传输协议…

互联网怎样利用人性-思维导图-markdown

互联网怎样利用人性 傲慢 留言、点评饥饿营销、吵架营销 懒惰 一键下单、扫二维码默认登录、多平台同步单点登录SSO美女论坛、美女头像事业线开箱防御力破女性装饰 贪婪 团购、秒杀、抽奖免费试吃、下载存储空间、在家赚钱晒单返现 窥视 订阅、悄悄关注名人博客微博、惊人标题…

javascript-es6 (五)

内置构造函数 在 JavaScript 中 最主要 的数据类型有 6 种&#xff1a; 基本数据类型&#xff1a; 字符串、数值、布尔、undefined、null 引用类型: 对象 但是&#xff0c;我们会发现有些特殊情况&#xff1a; //普通字符串 const str peiqi console.log(str.length) //…

Hive从入门到运用

hive简介 hive的设计思想&#xff08;本质是一个翻译器&#xff09; 上传安装包 解压&#xff0c;查看 运行hive&#xff08;一定要启动hadoop&#xff0c;是有依赖关系的。&#xff09; 测试启动方法&#xff0c;和建表 文件创建很上传到hdfs&#xff0c;直接上传到hive表的目…

RK3588部署YOLOv8(1):YOLOv8和YOLOv8-pose转ONNX及Python后处理代码实现

前言 由于种种原因&#xff0c;原始的YOLOv8系列的模型&#xff0c;在RK3588上难以部署&#xff0c;在 .pt 转 .onnx 的时候需要去掉后处理层&#xff08;主要是DFL层&#xff09;。因此&#xff0c;模型的后处理需要自己来实现。 本文基于Rockship 官方给的源码&#xff08;导…

Lua的table(表)

Lua表的基本概念 Lua中的表&#xff08;table&#xff09;是一种多功能数据结构&#xff0c;可以用作数组、字典、集合等。表是Lua中唯一的数据结构机制&#xff0c;其他数据结构如数组、列表、队列等都可以通过表来实现。 表的实现 Lua的表由两部分组成&#xff1a; 数组部分…

权限(1)

权限1 一、shell命令及运行原理二、linux中的用户1、身份切换 2、sudo &#xff1a;指令的短暂提权&#xff08;输入用户自己的密码&#xff09;3、权限理解4、拥有者&#xff0c;所属组&#xff0c;other5&#xff0c;文件属性6、修改权限&#xff08;角色 / 属性&#xff09;…

【实战】使用PCA可视化神经网络提取后的特征空间【附源码】

《------往期经典推荐------》 一、AI应用软件开发实战专栏【链接】 项目名称项目名称1.【人脸识别与管理系统开发】2.【车牌识别与自动收费管理系统开发】3.【手势识别系统开发】4.【人脸面部活体检测系统开发】5.【图片风格快速迁移软件开发】6.【人脸表表情识别系统】7.【…

Lumoz Chain正式上线:AI 时代的新算力破局者

新的叙事和技术突破永远是推动行业前行的核心动力。当下&#xff0c;AI Agent无疑是最炙手可热的赛道之一。 当加密世界将目光投向AI领域时&#xff0c;大多数项目仍停留在以AI为工具或应用场景的层面&#xff0c;试图通过集成AI模型或优化链上功能来吸引用户。然而&#xff0c…

《如何利用看板工具提升学习效率?》

从零开始&#xff1a;用看板工具打造高效学习管理系统 在当今这个信息爆炸的时代&#xff0c;知识更新换代的速度快得惊人&#xff0c;无论是学生、职场人士还是终身学习者&#xff0c;都面临着如何有效管理学习过程、提升学习效率的难题。而板栗看板这款软件&#xff0c;或许…

基于STM32的智能垃圾分类与回收系统

1. 引言 传统垃圾处理方式存在分类效率低、资源浪费严重等问题&#xff0c;难以满足城市可持续发展的需求。本文设计了一款基于STM32的智能垃圾分类与回收系统&#xff0c;通过视觉识别、多传感器融合与自动化分拣技术&#xff0c;实现垃圾精准分类、压缩存储与资源回收&#…