项目小记1:跨域,常用的查看性能linux命令,安装mysql,云端部署springboot项目部署脚本,内嵌tomcat的优化

spring解决跨域请求问题

1、后端

接受跨域的所有请求,允许接受ajax请求

在注解上添加字段

@CrossOrigin(allowedHeaders = "*", allowCredentials = "true")

常用的linux命令(在云端部署中使用的命令)

chmod 777 xxx 改变文件的权限
rpm -ivh xxx 红帽解压
ps -ef|grep mysql 查看进程
netstat -anp|grep 3306 查看端口号被谁使用
安装mysql
yum install mysql*
yum install mariadb-server
systemctl start mariadb.service
ps -ef|grep mysql 查看进程 ps -ef|grep java
netstat -anp|grep 3306 查看端口号被谁使用
linux运行项目自定义配置(有则覆盖无则用之)
java -jar xxx.jar --spring.config.addition-      location=application.properties (自定义配置文件)
编写部署脚本文件
deploy.sh(文件名)
nohup java -Xmx400m -Xms400m -XX:NewSize=200m -XX:MaxNewSize=200m -jar xxx.jar --spring.config.addition-location=application.properties   (application.properties配置文件我使用的时相对路径)
启动:./deploy.sh &
pstree -p 端口号  查看线程树
pstree -p 端口号 | wc -l 查看线程数
top -H 查看linux的性能
springboot-tomcat的配置(内嵌)(2.0版本)
配置文件
server.tomcat.accept-count:等待队列长度,默认100
server.tomcat.max-connections:最大可被连接数,默认10000
server.tomcat.max-threads:最大工作线程数,默认200
server.tomcat.min-spare-threads:最小工作线程数,默认10
默认配置下,连接超过10000后出现拒绝连接情况
默认配置下,触发的请求超过200+100后拒绝处理
server.tomcat.accept-count:1000
server.tomcat.max-threads:800
server.tomcat.min-spare-threads:100
类的自定义
keepAliveTimeOut:多少毫秒后不响应的断开keepalive
maxKeepAliveRequests :多少次请求后keepalive断开失效
使用WebServerFactoryCustomizer<ConfigurableServletWeb
ServerFactory>定制化内嵌tomcat配置
//容器中没有TomcatEmbeddedServletContainerFactory这个bean时会把bean加载进spring中
@Component
public class WebServerConfiguration implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
    @Override
    public void customize(ConfigurableWebServerFactory factory) {

        ((TomcatServletWebServerFactory) factory).addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
                //定制化keepAliveTimeout,设置30秒内没有请求则服务端自动断开
                protocol.setKeepAliveTimeout(30000);
                //当客户端发送超过10000哥请求则自动断开keeplive连接
                protocol.setMaxKeepAliveRequests(10000);
            }
        });

    }
}

web容器上限

线程数量∶4核cpu 8G内存单进程调度线程数800-1000以上后即花费巨大的时间在cpu调度上
等待队列长度:队列做缓冲池用,但也不能无限长,消耗内存,出队入队也耗cpu

MySql数据库QPS容量问题

主键查询:千万级别数据=1-10毫秒
唯一索引查询:千万级别数据=10-100毫秒
非唯一索引查询:千万级别数据=100-1000毫秒
无索引∶百万条数据= 1000毫秒+

2、前端

如果使用ajax请求

需添加
xhrFields: {withCredentials: true},

 $.ajax({
                type: "POST",
                contentType: "application/x-www-form-urlencoded",
                url: "http://localhost:8080/register",
                data: {
                    "telphone": tel,
                    "name": name,
                    "gender": gender,
                    "age": age,
                    "code": code,
                    "password": password
                },
                //使ajax请求成为可授信
                xhrFields: {withCredentials: true},
                success: function (res) {
                    if (res.status == "success") {
                        alert("注册" + res.status)
                    } else {
                        alert(res.data.msg)
                    }
                },
                error: function () {
                    alert("获取数据错误")
                }
            })
            return false;
        })

获取路径中的参数

 function getParams(str) {
        var t = new RegExp("(^|&)" + str + "=([^&]*)(&|$)"),
            n = window.location.search.substr(1).match(t);
        // window.location.search 设置或获取 href 属性中跟在问号后面的部分。
        return null != n ? n[2] : null
    }

设置定时器

//1秒执行一次函数
setInterval(轮询的函数, 1000)

倒计时

把时间中的"-"替换调
例如:秒杀开始时间
var date = itemInfo.satrtTime.replace(new RegExp("-", "gm"), "/")
		//获取时间位毫秒单位
            date = (new Date(date)).getTime()
         //获取当前时间   
            var nowTime = Date.parse(new Date())
            //倒计时
            var delta = (date - nowTime) / 1000
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值