#
有時查看LINUX時,會發現當前CPU消耗連續保持80%,如何找出是哪個應用呢?
top -i //輸出應用列表,并隱藏IDEL的應用
P //在列表時,按P,則按CPU的使用排序
How To Check CPU Utilization In Linux With Command Line
https://phoenixnap.com/kb/check-cpu-usage-load-linux
很久以前多線程是這樣創建:
Thread t1 = new Thread();
Thread t2 = new Thread();
t1.start(); // 啟動新線程
t2.start(); // 啟動新線程
由于創建和銷毀線程是非常耗資源,因此改成線程建好后不銷毀,可以重用,用戶只需提供run方法的具體實現:
public static void main(String[] args) throws Exception {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<String> stringFuture = executor.submit(new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep(2000);
return "async thread";
}
});
Thread.sleep(1000);
System.out.println("main thread");
System.out.println(stringFuture.get());
}
但如果很多線程被創建,并且線程間有依賴,即按流程和條件執行線程,實現起來就有點復雜,于是CompletableFuture橫空出世。一共有50各方法可供使用。
CompletableFuture.supplyAsync(),相當于創建了ExecutorService,同時也創建了Callable,然后提交到線程池中執行。
CompletableFuture<String> futureA = CompletableFuture.supplyAsync(() -> "任務A");
CompletableFuture<String> futureB = CompletableFuture.supplyAsync(() -> "任務B");
CompletableFuture<String> futureC = futureB.thenApply(b -> {
System.out.println("執行任務C.");
System.out.println("參數:" + b);//參數:任務B
return "a";
});
!!How to use CompletableFuture and Callable in Java
https://ducmanhphan.github.io/2020-02-10-How-to-use-CompletableFuture-Callable-in-Java/使用CompletableFuture優化你的代碼執行效率
https://www.cnblogs.com/fingerboy/p/9948736.htmlCompletableFuture 使用詳解
https://www.jianshu.com/p/6bac52527ca4使用CompletableFuture
https://www.liaoxuefeng.com/wiki/1252599548343744/1306581182447650https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-concurrency-basic/src/test/java/com/baeldung/completablefuture/CompletableFutureLongRunningUnitTest.java
/etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
#symbolic-links=0
#vish start
open_files_limit = 8000
max_connections = 500
#set-variable=max_connections=500
thread_concurrency = 8
#concurrent_insert=2
thread_cache_size=2000
interactive_timeout=180
wait_timeout=180
max_allowed_packet = 32M
key_buffer_size = 3000M
read_buffer_size = 16M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 256M
myisam_sort_buffer_size = 16M
myisam_max_sort_file_size = 256M
myisam_repair_threads = 1
#myisam_recover = 4
max_heap_table_size = 2048M
tmp_table_size = 1024M
table_open_cache = 2000
table_cache = 2000
sort_buffer_size = 128M
join_buffer_size = 128M
query_cache_size = 128M
query_cache_limit = 128M
#slow_query_log=1
log-slow-queries
long_query_time=2
#log_queries_not_using_indexes=1
slow_query_log_file = /var/log/mariadb/host_name-slow.log
[mysqldump]
user=root
password=*********
#max_allowed_packet = 1024M
[myisamchk]
key_buffer_size = 2500M
sort_buffer_size = 1024M
read_buffer = 32M
write_buffer = 32M
[innodb]
innodb_buffer_pool_size=3G
innodb_buffer_pool_instance=2
innodb_additional_mem_pool_size=20M
innodb_log_file_size= 512M
innodb_log_buffer_size=16M
innodb_flush_log_at_trx_commit=1
innodb_thread_concurrency=16
#innodb_read_io_threads=16
#innodb_write_io_threads=16
#innodb_io_capacity=2000
#innodb_lock_wait_timeout=120
innodb_flush_method=O_DIRECT
#vish end
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#!includedir /etc/my.cnf.d
1、將當前目錄下包含jack串的文件中,jack字符串替換為tom
sed -i "s/jack/tom/g" `grep "jack" -rl ./`
2、將某個文件中的jack字符串替換為tom
sed -i "s/jack/tom/g" test.txt
參考連接:http://blog.csdn.net/lizhi200404520/article/details/7968483
JMETER作為一個壓力測試工具,可模擬上千用戶進行登錄之類的操作。
但一般圖形界面只用來制作測試計劃,真正運行是在LINUX上。
同時也可以作為壓測MYSQL數據庫等。
配置基本流程:添加測試計劃-->添加線程組,在添加的線程組中-->添加JDBC配置組件-->添加JDBC訪問的SQL語句的REQUEST組件-->配置REQUEST和配置組件相關聯的變量值-->添加查看結果組件-->設定要運行的線程數-->執行。
執行期間如有問題,查看DOS窗口。
【JMeter】JMeter完成一個MySql壓力測試
https://www.cnblogs.com/zhaoxd07/p/4895681.htmlJMeter 如何與 MySQL 進行整合測試
https://juejin.im/post/6844903728215162887JMeter JDBC連接MySql配置
https://www.jianshu.com/p/cde2729421d1jmeter(二十五)linux環境運行jmeter并生成報告
https://www.cnblogs.com/imyalost/p/9808079.html
MARIADB的默認最大連接數是100,當試圖更改配置文件/etc/my.conf追加max_connections=1000,并重啟服務時,發現最大連接數被重置為214,這是由于系統問題,open_files數為1024,如何正確地更改是個復雜的問題。
MARIADB中一些查當前連接數/最大連接數的命令為:
MariaDB [(none)]>
show variables like "max_connections";
show processlist;
show status where variable_name = 'threads_connected';
show status where variable_name = 'max_used_connections';
show variables like 'max_user_connections';
show variables like '%connection%';
正確方案:
RHEL\CentOS 7 下 MySQL 連接數被限制為214個
https://waylau.com/rhel-mysql-connections-limit-214/
Centos7.4下面mysql的max_connections不生效的問題。
https://blog.51cto.com/wangqh/2131340
為何要在SERVICE中添加允許打開的文件數?
Centos7下修改/etc/security/limits.conf文件只在用戶登錄后打開的進程有效,系統服務或通過rc.local啟動的無效,系統服務修改文件/usr/lib/systemd/system/SOME_SERVICE.service添加:
[Service]
LimitNOFILE=65535
關于LINUX系統的最大打開文件數:
https://blog.51cto.com/as007012/1956222https://www.haiyun.me/archives/linux-file-limit.html