Nginx下Go的多种使用方式性能比较

Nginx部署GO语言应用程序 这里写自定义目录标题Nginx部署GO语言应用程序Nginx是什么名词解释Nginx的安装Nginx常用命令 Nginx部署GO语言应用程序 使用nginx部署go语言应用程序实现反向代理和负载均衡 Nginx是什么 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,可以用于负载均衡、邮件代理、TCP/UDP、HTTP服务器等等 ,其特点如下: 正向、反向代理 负载均衡 支持TLS/SSL与SN 阅读详情

结论:Go HTTP standalone >(优于)   Nginx proxy to Go HTTP >(优于) Nginx fastcgi to Go TCP FastCGI


原文链接:http://www.oschina.net/translate/benchmarking-nginx-with-go?from=20131222

英文链接:https://gist.github.com/hgfischer/7965620

目前有很多提供Go语言HTTP应用服务的方法,但其中最好的选择取决于每个应用的实际情况。目前,Nginx看起来是每个新项目的标准Web服务器,即使在有其他许多不错Web服务器的情况下。然而,在Nginx上提供Go应用服务的开销是多少呢?我们需要一些nginx的特性参数(vhosts,负载均衡,缓存,等等)或者直接使用Go提供服务?如果你需要nginx,最快的连接机制是什么?这就是在这我试图回答的问题。该基准测试的目的不是要验证Go比nginx的快或慢。那将会很愚蠢。

下面是我们要比较不同的设置:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI

硬件

因为我们将在相同的硬件下比较所有设置,硬件选择的是廉价的一个。这不应该是一个大问题。

  • Samsung 笔记本 NP550P5C-AD1BR
  • Intel Core i7 3630QM @2.4GHz (quad core, 8 threads)
  • CPU caches: (L1: 256KiB, L2: 1MiB, L3: 6MiB)
  • RAM 8GiB DDR3 1600MHz

软件

  • Ubuntu 13.10 amd64 Saucy Salamander (updated)
  • Nginx 1.4.4 (1.4.4-1~saucy0 amd64)
  • Go 1.2 (linux/amd64)
  • wrk 3.0.4

设置

内核

只需很小的一点调整,将内核的limits调高。如果你对这一变量有更好的想法,请在写在下面评论处:

01 fs.file-max                    9999999
02 fs.nr_open                     9999999
03 net.core.netdev_max_backlog    4096
04 net.core.rmem_max              16777216
05 net.core.somaxconn             65535
06 net.core.wmem_max              16777216
07 net.ipv4.ip_forward            0
08 net.ipv4.ip_local_port_range   1025       65535
09 net.ipv4.tcp_fin_timeout       30
10 net.ipv4.tcp_keepalive_time    30
11 net.ipv4.tcp_max_syn_backlog   20480
12 net.ipv4.tcp_max_tw_buckets    400000
13 net.ipv4.tcp_no_metrics_save   1
14 net.ipv4.tcp_syn_retries       2
15 net.ipv4.tcp_synack_retries    2
16 net.ipv4.tcp_tw_recycle        1
17 net.ipv4.tcp_tw_reuse          1
18 vm.min_free_kbytes             65536
19 vm.overcommit_memory           1

Limits

供root和www-data打开的最大文件数限制被配置为200000。

Nginx

有几个必需得Nginx调整。有人跟我说过,我禁用了gzip以保证比较公平。下面是它的配置文件/etc/nginx/nginx.conf:

01 user www-data;
02 worker_processes auto;
03 worker_rlimit_nofile 200000;
04 pid /var/run/nginx.pid;
05  
06 events {
07     worker_connections 10000;
08     use epoll;
09     multi_accept on;
10 }
11  
12 http {
13     sendfile on;
14     tcp_nopush on;
15     tcp_nodelay on;
16     keepalive_timeout 300;
17     keepalive_requests 10000;
18     types_hash_max_size 2048;
19  
20     open_file_cache max=200000 inactive=300s;
21     open_file_cache_valid 300s;
22     open_file_cache_min_uses 2;
23     open_file_cache_errors on;
24  
25     server_tokens off;
26     dav_methods off;
27  
28     include /etc/nginx/mime.types;
29     default_type application/octet-stream;
30  
31     access_log /var/log/nginx/access.log combined;
32     error_log /var/log/nginx/error.log warn;
33  
34     gzip off;
35     gzip_vary off;
36  
37     include /etc/nginx/conf.d/*.conf;
38     include /etc/nginx/sites-enabled/*.conf;
39 }

Nginx vhosts

01 upstream go_http {
02     server 127.0.0.1:8080;
03     keepalive 300;
04 }
05  
06 server {
07     listen 80;
08     server_name go.http;
09     access_log off;
10     error_log /dev/null crit;
11  
12     location / {
13         proxy_pass http://go_http;
14         proxy_http_version 1.1;
15         proxy_set_header Connection "";
16     }
17 }
18  
19 upstream go_fcgi_tcp {
20     server 127.0.0.1:9001;
21     keepalive 300;
22 }
23  
24 server {
25     listen 80;
26     server_name go.fcgi.tcp;
27     access_log off;
28     error_log /dev/null crit;
29  
30     location / {
31         include fastcgi_params;
32         fastcgi_keep_conn on;
33         fastcgi_pass go_fcgi_tcp;
34     }
35 }
36  
37 upstream go_fcgi_unix {
38     server unix:/tmp/go.sock;
39     keepalive 300;
40 }
41  
42 server {
43     listen 80;
44     server_name go.fcgi.unix;
45     access_log off;
46     error_log /dev/null crit;
47  
48     location / {
49         include fastcgi_params;
50         fastcgi_keep_conn on;
51         fastcgi_pass go_fcgi_unix;
52     }
53 }

Go源码

01 package main
02  
03 import (
04     "fmt"
05     "log"
06     "net"
07     "net/http"
08     "net/http/fcgi"
09     "os"
10     "os/signal"
11     "syscall"
12 )
13  
14 var (
15     abort bool
16 )
17  
18 const (
19     SOCK = "/tmp/go.sock"
20 )
21  
22 type Server struct {
23 }
24  
25 func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
26     body := "Hello World\n"
27     // Try to keep the same amount of headers
28     w.Header().Set("Server", "gophr")
29     w.Header().Set("Connection", "keep-alive")
30     w.Header().Set("Content-Type", "text/plain")
31     w.Header().Set("Content-Length", fmt.Sprint(len(body)))
32     fmt.Fprint(w, body)
33 }
34  
35 func main() {
36     sigchan := make(chan os.Signal, 1)
37     signal.Notify(sigchan, os.Interrupt)
38     signal.Notify(sigchan, syscall.SIGTERM)
39  
40     server := Server{}
41  
42     go func() {
43         http.Handle("/", server)
44         if err := http.ListenAndServe(":8080", nil); err != nil {
45             log.Fatal(err)
46         }
47     }()
48  
49     go func() {
50         tcp, err := net.Listen("tcp", ":9001")
51         if err != nil {
52             log.Fatal(err)
53         }
54         fcgi.Serve(tcp, server)
55     }()
56  
57     go func() {
58         unix, err := net.Listen("unix", SOCK)
59         if err != nil {
60             log.Fatal(err)
61         }
62         fcgi.Serve(unix, server)
63     }()
64  
65     <-sigchan
66  
67     if err := os.Remove(SOCK); err != nil {
68         log.Fatal(err)
69     }
70 }

检查HTTP header

为公平起见,所有的请求必需大小相同。

01 $ curl -sI http://127.0.0.1:8080/
02 HTTP/1.1 200 OK
03 Connection: keep-alive
04 Content-Length: 12
05 Content-Type: text/plain
06 Server: gophr
07 Date: Sun, 15 Dec 2013 14:59:14 GMT
08  
09 $ curl -sI http://127.0.0.1:8080/ | wc -c
10 141
01 $ curl -sI http://go.http/
02 HTTP/1.1 200 OK
03 Server: nginx
04 Date: Sun, 15 Dec 2013 14:59:31 GMT
05 Content-Type: text/plain
06 Content-Length: 12
07 Connection: keep-alive
08  
09 $ curl -sI http://go.http/ | wc -c
10 141
01 $ curl -sI http://go.fcgi.tcp/
02 HTTP/1.1 200 OK
03 Content-Type: text/plain
04 Content-Length: 12
05 Connection: keep-alive
06 Date: Sun, 15 Dec 2013 14:59:40 GMT
07 Server: gophr
08  
09 $ curl -sI http://go.fcgi.tcp/ | wc -c
10 141
01 $ curl -sI http://go.fcgi.unix/
02 HTTP/1.1 200 OK
03 Content-Type: text/plain
04 Content-Length: 12
05 Connection: keep-alive
06 Date: Sun, 15 Dec 2013 15:00:15 GMT
07 Server: gophr
08  
09 $ curl -sI http://go.fcgi.unix/ | wc -c
10 141

启动引擎

  • 使用sysctl配置内核
  • 配置Nginx
  • 配置Nginx vhosts
  • 用www-data启动服务
  • 运行基准测试

基准测试

GOMAXPROCS = 1
Go standalone
1 # wrk -t100 -c5000 -d30s http://127.0.0.1:8080/
2 Running 30s test @ http://127.0.0.1:8080/
3   100 threads and 5000 connections
4   Thread Stats   Avg      Stdev     Max   +/- Stdev
5     Latency   116.96ms   17.76ms 173.96ms   85.31%
6     Req/Sec   429.16     49.20   589.00     69.44%
7   1281567 requests in 29.98s, 215.11MB read
8 Requests/sec:  42745.15
9 Transfer/sec:      7.17MB
Nginx + Go through HTTP
1 # wrk -t100 -c5000 -d30s http://go.http/
2 Running 30s test @ http://go.http/
3   100 threads and 5000 connections
4   Thread Stats   Avg      Stdev     Max   +/- Stdev
5     Latency   124.57ms   18.26ms 209.70ms   80.17%
6     Req/Sec   406.29     56.94     0.87k    89.41%
7   1198450 requests in 29.97s, 201.16MB read
8 Requests/sec:  39991.57
9 Transfer/sec:      6.71MB
Nginx + Go through FastCGI TCP
01 # wrk -t100 -c5000 -d30s http://go.fcgi.tcp/
02 Running 30s test @ http://go.fcgi.tcp/
03   100 threads and 5000 connections
04   Thread Stats   Avg      Stdev     Max   +/- Stdev
05     Latency   514.57ms  119.80ms   1.21s    71.85%
06     Req/Sec    97.18     22.56   263.00     79.59%
07   287416 requests in 30.00s, 48.24MB read
08   Socket errors: connect 0, read 0, write 0, timeout 661
09 Requests/sec:   9580.75
10 Transfer/sec:      1.61MB
Nginx + Go through FastCGI Unix Socket
01 # wrk -t100 -c5000 -d30s http://go.fcgi.unix/
02 Running 30s test @ http://go.fcgi.unix/
03   100 threads and 5000 connections
04   Thread Stats   Avg      Stdev     Max   +/- Stdev
05     Latency   425.64ms   80.53ms 925.03ms   76.88%
06     Req/Sec   117.03     22.13   255.00     81.30%
07   350162 requests in 30.00s, 58.77MB read
08   Socket errors: connect 0, read 0, write 0, timeout 210
09 Requests/sec:  11670.72
10 Transfer/sec:      1.96MB
GOMAXPROCS = 8
Go standalone
1 # wrk -t100 -c5000 -d30s http://127.0.0.1:8080/
2 Running 30s test @ http://127.0.0.1:8080/
3   100 threads and 5000 connections
4   Thread Stats   Avg      Stdev     Max   +/- Stdev
5     Latency    39.25ms    8.49ms  86.45ms   81.39%
6     Req/Sec     1.29k   129.27     1.79k    69.23%
7   3837995 requests in 29.89s, 644.19MB read
8 Requests/sec: 128402.88
9 Transfer/sec:     21.55MB
Nginx + Go through HTTP
1 # wrk -t100 -c5000 -d30s http://go.http/
2 Running 30s test @ http://go.http/
3   100 threads and 5000 connections
4   Thread Stats   Avg      Stdev     Max   +/- Stdev
5     Latency   336.77ms  297.88ms 632.52ms   60.16%
6     Req/Sec     2.36k     2.99k   19.11k    84.83%
7   2232068 requests in 29.98s, 374.64MB read
8 Requests/sec:  74442.91
9 Transfer/sec:     12.49MB
Nginx + Go through FastCGI TCP
01 # wrk -t100 -c5000 -d30s http://go.fcgi.tcp/
02 Running 30s test @ http://go.fcgi.tcp/
03   100 threads and 5000 connections
04   Thread Stats   Avg      Stdev     Max   +/- Stdev
05     Latency   217.69ms  121.22ms   1.80s    75.14%
06     Req/Sec   263.09    102.78   629.00     62.54%
07   721027 requests in 30.01s, 121.02MB read
08   Socket errors: connect 0, read 0, write 176, timeout 1343
09 Requests/sec:  24026.50
10 Transfer/sec:      4.03MB
Nginx + Go through FastCGI Unix Socket
1 # wrk -t100 -c5000 -d30s http://go.fcgi.unix/
2 Running 30s test @ http://go.fcgi.unix/
3   100 threads and 5000 connections
4   Thread Stats   Avg      Stdev     Max   +/- Stdev
5     Latency   694.32ms  332.27ms   1.79s    62.13%
6     Req/Sec   646.86    669.65     6.11k    87.80%
7   909836 requests in 30.00s, 152.71MB read
8 Requests/sec:  30324.77
9 Transfer/sec:      5.09MB

结论

第一组基准测试时一些Nginx的设置还没有很好的优化(启用gzip,Go的后端没有使用keep-alive连接)。当改为wrk以及按建议优化Nginx后结果有较大差异。

当GOMAXPROCS=1时,Nginx的开销不是那么大,但当OMAXPROCS=8时差异就很大了。以后可能会再试一下其他设置。如果你需要使用Nginx像虚拟主机,负载均衡,缓存等特性,使用HTTP proxy,别使用FastCGI。有些人说Go的FastCGI还没有被很好优化,这也许就是测试结果中巨大差异的原因。

Gin、Go HTTP库、ReverseProxy、Nginx代理性能压测 笔记本(英特尔 i7 8700HQ),分配内存4G, 4核CPU虚拟机进行试验 1、Gin func main) { router := gin.New() router.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{"message": "pong"}) }) server := &http.Server{ Addr: addr, WriteTimeout: time.Second * 3, Ha 阅读详情

相关推荐

Go字符串比较的五大陷阱与高性能选型指南

字符串比较是编程中最基础却极易被误用的操作,其本质涉及内存布局、Unicode语义、大小写折叠规则及运行时开销等多维权衡。在Go中,`==`虽为O(1)字节比较,但无法处理大小写不敏感或Unicode规范化需求;而`strings.ToLower`因强制内存分配和简单映射,既存在语义缺陷(如无法正确处理'ß'→'ss'),又引发GC压力。相比之下,`strings.EqualFold`基于Unicode标准UAX #44实现Full Case Folding,兼顾语义正确性与零堆内存分配,在HTTP头校验、

weixin_34195546的博客 443

GO+Nginx实现服务器的高并发+负载均衡(超级简单,开箱即用)

Go部分的代码,我没怎么详细讲,大概意思大家应该能看懂,里面我还使用了令牌桶来对请求当前api的连接数做了限制,可以在Nginx的ip限制下再做一次限制,可以简单达到下面的两个功能保护服务器资源:通过限制请求数,可以防止服务器过载。当同时接收到大量的请求时,服务器的资源(如 CPU、内存和网络带宽)可能会耗尽,导致性能下降甚至崩溃。通过限制请求数,可以确保服务器能够合理地处理请求,避免资源耗尽。提高系统稳定性:通过限制请求数,可以防止某些恶意用户或恶意程序通过发送大量请求来攻击服务器。

qq_41866988的博客 2023

告别Nginx!用Go的embed把Vue前端直接塞进Golang可执行文件(附go-admin实战)

本文详细介绍了如何利用Go的embed特性将Vue前端直接嵌入Golang可执行文件,实现前后端单文件部署的革命性方案。通过go-admin实战案例,展示了如何简化部署流程、消除Nginx依赖,特别适合中小型Web应用和内部管理系统。文章涵盖环境配置、项目结构优化、前后端集成技巧以及跨平台构建等核心内容。

weixin_30736301的博客 204

对Go+Nginx 进行性能测试

原文链接:http://www.oschina.net/translate/benchmarking-nginx-with-go?from=20131222 英文链接:https://gist.github.com/hgfischer/7965620 目前有很多提供Go语言HTTP应用服务的方法,但其中最好的选择取决于每个应用的实际情况。目前,Nginx看起来是每个新项目的标准Web服

雕刻时间的专栏 1778

[Vue][面试]谈谈你对MVC、MVP和MVVM的理解

谈谈你对MVC、MVP和MVVM的理解 答题思路:此题涉及知识点很多,很难说清楚,说透彻,因为MVC,MVP这些我们前端程序员自己甚至都没用过。但是恰恰反映了前端这些年从无到有, 从有到优的变迁过程,因此沿此思路回答将十分清除。 Web1.0时代 在web1.0时代,并没有前端的概念。开发一个web应用多数采用ASP.NET/Java/PHP编写,项目通常由多个aspx/jsp/php文件构成,每个文件中同时包含了HTML、CSS、JavaScript、C#/Java/PHP代码, 系统整体架构可能如下图所

你好,欢迎光临! 731

LVDS信号调试必备:5分钟搞懂Xilinx IDELAYE3的TIME模式校准

本文深入解析了在Xilinx Ultrascale系列FPGA中调试LVDS信号时,如何正确使用IDELAYE3的TIME模式进行精密延迟校准。文章重点阐述了IDELAYCTRL、EN_VTC管脚与校准状态机的协同工作机制,揭秘了内置自校准(BISC)中Align_Delay的影响,并提供了从抽头值计算到实际眼图优化的完整实战方案,帮助工程师快速解决高速接口的时序问题。

joy55的博客 227

golang入门笔记——nginx

Nginx是一个高性能的HTTP和反向代理服务器,特点是占用内存少,并发能力强,Nginx专为性能优化而开发,能经受高负载的考验,有报告表明能支持高达50000个并发连接数。正向代理:通过代理服务器访问目标服务器,我们知道目标服务器的链接,但无法直接访问目标服务器,必须通过代理的方式访问。反向代理:一个请求访问目标服务器时,请求先到达代理服务器,由代理服务器转发给目标服务器,此时反向代理服务器和目标服务器对外就是一个服务器,暴露的是代理服务器地址,隐藏了真实服务器IP地址。

qq_43716830的博客 2576

【LPDDR4 - 学习二】LPDDR4 介绍 ——LPDDR4 芯片引脚说明解析

本文系统解析了LPDDR4内存芯片的引脚定义与特性,重点介绍了272球POPFBGA封装的双通道架构。内容涵盖电源管理(三级供电架构与上电时序)、控制信号(差分时钟与复用命令总线)、数据接口(16位双向数据总线与选通信号)以及校准复位等核心模块。通过表格详细列明了各引脚电压范围、功能定义及工程注意事项,并附有典型封装球位分布图。全文基于JEDEC标准,为移动设备内存设计提供全面的硬件参考,特别强调电源时序控制、信号完整性及抗干扰设计等关键点。

zap15622077817的博客 2666

用Nginx部署Go应用

Nginx 是一个 Web Server,可以用作反向代理、负载均衡、邮件代理、TCP / UDP、HTTP 服务器等等,它拥有很多吸引人的特性,例如: 以较低的内存占用率处理 10,000 多个并发连接(每10k非活动HTTP保持活动连接约2.5 MB ) 静态服务器(处理静态文件) 正向、反向代理 负载均衡 通过OpenSSL 对 TLS / SSL 与 SNI 和 OCSP 支持 FastCGI、SCGI、uWSGI 的支持 WebSo

编程哲学家的专栏 2777

从零开始:用ADS 2023手把手教你设计2.4GHz Wi-Fi LNA(基于ATF-54143,附模型文件)

本文详细介绍了如何使用ADS 2023软件设计2.4GHz Wi-Fi频段的低噪声放大器(LNA),基于ATF-54143晶体管。内容涵盖模型导入、直流工作点确定、稳定性优化、噪声匹配等关键步骤,并提供可下载的模型文件包,帮助工程师快速掌握LNA设计技巧。

weixin_42531128的博客 334

避坑指南:Cursor AI生成Flutter代码时最容易翻车的5个配置细节

本文深入剖析了使用Cursor AI生成Flutter代码时,因.cursorrules配置文件不当而导致的五大常见问题。重点探讨了如何通过制定清晰、具体的规则,避免状态管理混乱、设计图输入低效、项目架构脱节、性能隐患及规则维护缺失等陷阱,从而将AI转化为高效、可靠的开发伙伴,提升代码质量和团队协作效率。

wdx0123456的博客 419

boot4go-gateway和nginx的性能测试大PK

为什么进行PK boot4go-gateway开源项目,是一个golang实现的高性能的gateway功能的项目, 在springcloud的项目里都是使用springcloud-gateway作为gateway的服务组件,springcloud虽然后面使用webflux实现了所有的gateway功能,提供springcloud环境里的API反向代理的功能,在性能能有了不错的提升,但是和nginx比较起来,毕竟是java系列的,即使使用netty作为底层通信的服务,但是在性能上和nginx还是差距了很大,

1186

Python爬虫 汽车之家 车型销量--参数分析与实现

【代码】Python爬虫 汽车之家 车型销量--参数分析与实现。

2201_76125393的博客 855

Go-Gateway反向代理,性能比拼Nginx

在以前的一篇文章《基于Fasthttp实现的Gateway,性能媲美Nginx。

2944

【第一章】基于Simulink的控制器开发教程——目录

摘要:本文系统介绍了基于Simulink的控制器开发方法,涵盖PID、状态反馈、模型预测(MPC)、模糊控制、自适应控制等8类主流控制器。针对每种控制器,详细阐述了其基本原理、适用场景,并通过Simulink建模与仿真测试进行实践验证。文章采用"理论+实践"的结构,从算法设计到硬件实现全流程展开,为汽车、航空航天、工业控制等领域的控制器开发提供完整解决方案,最后通过应用对比与学习总结帮助读者掌握不同控制器的核心特性和应用场景。(149字)

熟悉MATLAB/fpga/RK3588/LABVIEW/protus/单片机/dsp/Multisim 410

新版CKA2020-2020-10-13-真题试卷

2020年10月13日 真题 新版CKA考试已于2020年9月1日正式上线! 考试模式:线上考试 考试时间:2小时 认证有效期:3年 软件版本:Kubernetes v1.19 重考政策:可接受1次重考 经验水平:中級 题目数量:17题 01 Task - 英文 Create a new ClusterRole named deployment-clusterrole that only allows the creation of the following resource types: Depl

随笔记录-分享&记忆 2400

Nginx反向代理+Go服务实践

前言 在后端开发期间,会为前端或者平台上提供API服务接口,这时、我们看完今天的文章可以详细了解到Nginx反向代理到后端服务上的过程。 Nginx: 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。可以做反向代理、正向代理,静态服务器等。 负载均衡算法: upstrem支持4种负载均衡调度算法: 轮询(weight):每个请求按时间顺序逐一...

数据与工程工作,AI大模型应用 1818

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

性能不逊Nginx的Gateway,性能测试大PK

昨天的一文《》, 给大家介绍了一个Gateway的开源Go语言项目;boot4go-gateway是用springcloud-gateway的功能方式以golang实现的一个组件,功能上对等springcloud-gateway,集成的服务治理上目前仅支持etcd;nacos,zookeeper,zulu版本后期看情况是否继续支持,既然这个产品是为云原生诞生的,那么nacos,zookeeper这样云原生的非热门产品是否支持还在考虑中,目前主要是以etcd系列为主了。

1576

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

关于windows环境使用nginx的一些性能问题

最近在一个windows环境中部署nginx,遇到了以下问题:1. nginx启动了九个线程(1master+8woekr),但是所有链接都被1个woker接收,其余worker不工作2. 用户端访问web很慢,登录服务器使用127.0.0.1访问本地页面也很慢3. 已知服务器带宽、内存、磁盘读写均不存在任何瓶颈4. 服务器并发访问数大概在500-1500左右,ngxin只占用15%的cpu和少量内存5. 根据网上教程对nginx做了各种参数优化均不起作用。

LLittleF的博客 2331

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

BBS-Go:现代化社区平台的Golang架构解析与工程实践

在当今技术社区建设需求日益增长的背景下,BBS-Go作为一款基于Golang开发的轻量级开源社区系统,为开发团队提供了高性能、可扩展的论坛与问答平台解决方案。该系统采用现代化的微服务架构设计,集成了用户管理、内容发布、社交互动、权限控制等核心功能模块,特别适用于技术团队内部协作、开源项目社区建设以及企业知识库管理等多种应用场景。 ## 技术架构剖析 BBS-Go采用分层架构设计,将业务逻辑、数

gitblog_00643的博客 1038

nginx 日志分析及性能排查

最近一直在做性能排查,思路就是根据分析nginx日志,得到响应耗时的url、以及请求时间,再得到这段时间的请求量,并发量,分析是并发的原因,还是本身就比较慢,如果是应用本身的原因,只需要找到对应的代码,然后进行优化就好了 我找到的几个原因,基本就是后端sql运行的比较多,单次访问看不出来,但是人比较多的时候就比较慢了,人少的时候20-200毫秒,人多的时候,200-6000毫秒,优化之后基本保持...

GoodIdea 1180

如何快速实现NGINX性能监控?NGINX Prometheus Exporter完整指南

**NGINX Prometheus Exporter** 是一款专为 **NGINX** 和 **NGINX Plus** 打造的开源监控工具,通过 **Prometheus** 轻松收集服务器性能指标,帮助用户实时掌握系统运行状态。本文将详细介绍如何从零开始部署和配置这款工具,让服务器监控变得简单高效。 ## ???? 为什么选择NGINX Prometheus Exporter? 作为最流行...

gitblog_01018的博客 932

使用Docker部署全栈Web应用:Nginx+Go+MySQL实战

本文详细介绍了使用Docker容器化技术部署全栈Web应用的完整流程。通过一个HR管理系统案例,展示了Nginx前端、Go后端和MySQL数据库的Docker化部署方案,包括Dockerfile编写、Docker Compose服务编排、健康检查配置等核心技术。文章重点讲解了环境一致性保障、安全加固措施和性能优化建议,并提供了常用运维命令。这种容器化部署方式实现了快速部署、资源隔离和版本控制,有效解决了传统部署方式的环境差异问题,是现代化DevOps实践的重要组成部分。

2401_87394161的博客 1196

linux环境下go-fastdfs安装及使用

linux环境下go-fastdfs安装及使用一.go-fastdfs简介二.安装2.1 二进制安装2.2 安装 一.go-fastdfs简介 go-fastdfs是一个基于http协议的分布式文件系统,具备高性能、高可靠、无中心、免维护等优点。以下内容抄官网: 特点: 支持curl命令上传 支持浏览器上传 支持HTTP下载 支持多机自动同步 支持断点下载 支持配置自动生成 支持小文件自动合并(减少inode占用) 支持秒传 支持跨域访问 支持一键迁移 支持并行体验 支持断点续传(tus) 支持dock

冰之杍的博客 8175

golang mysql跟php mysql,Ubuntu 下 nginx , php , mysql 和 golang 的简单安装

我是搞php出身,自然安装lnmp是常规技能。以前的手段还是lnmp安装包,比如军哥的lnmp1.0。随着php和mysql的更新,大多数一键安装都开始版本老化,更新困难的问题。因此,重新研究了一下Ubuntu下lnmp的安装,发现现在简单的多,记录一下。另外最近在学习golang,Ubuntu下安装自然也是必须的过程。不过golang的安装也有一些奥妙。当然,不是源码安装的啦。Nginx Sta...

weixin_30260057的博客 195
上一篇: Ubuntu+Nginx+PHP之配置
下一篇: ubuntu下GOROOT和GOPATH配置
typ2004
博客等级 码龄17年 48粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值