- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在即将成为生产环境的 Django/Tastypie 上运行,但是我注意到使用 Apache 与使用内置开发服务器相比开销很大。 Apache 慢得多。
以下是使用 ab 的非科学带宽测试:
Apache :
$ ab -n 100 -c 50 https://www.mydomain.com/api/v1/clock/?format=json
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.mydomain.com (be patient).....done
Server Software: Apache/2.2.22
Server Hostname: www.mydomain.com
Server Port: 443
SSL/TLS Protocol: TLSv1/SSLv3,AES256-SHA,2048,256
Document Path: /api/v1/clock/?format=json
Document Length: 295 bytes
Concurrency Level: 50
Time taken for tests: 1.313 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Non-2xx responses: 100
Total transferred: 49800 bytes
HTML transferred: 29500 bytes
Requests per second: 76.15 [#/sec] (mean)
Time per request: 656.634 [ms] (mean)
Time per request: 13.133 [ms] (mean, across all concurrent requests)
Transfer rate: 37.03 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 15 283 162.5 282 590
Processing: 55 324 148.4 306 622
Waiting: 55 319 150.2 305 621
Total: 110 607 138.8 619 712
Percentage of the requests served within a certain time (ms)
50% 619
66% 691
75% 692
80% 701
90% 709
95% 709
98% 711
99% 712
100% 712 (longest request)
开发服务器(manage.py runserver):
$ ab -n 100 -c 50 http://127.0.0.1:8000/api/v1/clock/?format=json
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software: WSGIServer/0.1
Server Hostname: 127.0.0.1
Server Port: 8000
Document Path: /api/v1/clock/?format=json
Document Length: 381 bytes
Concurrency Level: 50
Time taken for tests: 0.701 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 54500 bytes
HTML transferred: 38100 bytes
Requests per second: 142.59 [#/sec] (mean)
Time per request: 350.656 [ms] (mean)
Time per request: 7.013 [ms] (mean, across all concurrent requests)
Transfer rate: 75.89 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.9 0 7
Processing: 43 73 47.0 63 365
Waiting: 31 70 47.0 61 365
Total: 50 74 47.0 64 365
Percentage of the requests served within a certain time (ms)
50% 64
66% 67
75% 69
80% 71
90% 77
95% 101
98% 276
99% 365
100% 365 (longest request)
如您所见,在较小的负载下,开发服务器的速度大约快 10 倍。即使在更高的负载下,它处理的请求也是原来的两倍。
我已经对 Apache 进行了基本修改以尝试解决这个问题,这似乎有点帮助,但是还有什么我遗漏的吗?我请求的“时钟”是一个非常基本的脚本,带有一个直接的数据库调用,因此连接或任何事情都没有什么奇怪的。它使用 Tastypie,因此输出为纯文本/json。似乎有些不对劲,因为开发服务器的请求速度要快得多。
这是我的 Apache 设置。它是在守护进程模式下在 worker MPM 上设置的:
KeepAlive Off
<IfModule mpm_worker_module>
StartServers 25
MinSpareThreads 25
MaxSpareThreads 300
ThreadLimit 64
ThreadsPerChild 25
MaxClients 300
MaxRequestsPerChild 0
</IfModule>
WSGIRestrictEmbedded On
虚拟主机添加:
WSGIDaemonProcess www.mydomain.com processes=4 threads=1
WSGIProcessGroup www.mydomain.com
WSGIScriptAlias / /var/www/domain/wsgi.py process-group=www.mydomain.com application-group=%{GLOBAL}
WSGIPassAuthorization On
Python/Tastypie 设置:
Debug = False
USE_I18N = False
USE_X_FORWARDED_HOST = True
它在负载均衡的 AWS 中型实例上运行,并且该服务器不提供任何静态文件,例如 images/css/js。我尝试在 IOPS/x-large 实例上提高它,但没有任何变化。数据库位于 Amazon RDS 上。但是在运行开发服务器时所有这些都是一样的,这告诉我托管环境不是问题。
任何帮助将不胜感激!!我现在真的不太担心高负载。这是一个基于 JSON 的 API,因此所有请求都是文本并且非常小。我最关心的是大量小请求的响应时间。
谢谢!标记
编辑:
我在 apache 上做了一个新的 ab 测试,将 dns 映射到本地主机。这与将其映射到 127.0.0.1 基本相同。这提供了更好的结果:
$ ab -n 100 -c 50 http://www.mydomain.com/api/v1/clock/?format=json
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.mydomain.com (be patient).....done
Server Software: Apache/2.2.22
Server Hostname: www.mydomain.com
Server Port: 80
Document Path: /api/v1/clock/?format=json
Document Length: 381 bytes
Concurrency Level: 50
Time taken for tests: 0.666 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 55900 bytes
HTML transferred: 38100 bytes
Requests per second: 150.22 [#/sec] (mean)
Time per request: 332.841 [ms] (mean)
Time per request: 6.657 [ms] (mean, across all concurrent requests)
Transfer rate: 82.01 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 3.0 2 6
Processing: 38 258 92.6 308 357
Waiting: 33 254 92.9 303 354
Total: 44 261 90.6 310 363
Percentage of the requests served within a certain time (ms)
50% 310
66% 321
75% 323
80% 327
90% 336
95% 344
98% 362
99% 363
100% 363 (longest request)
所以最初的测试是通过外部负载均衡器进行的。这些数字还可以,但是前 50% 的测试平均响应时间仍为 310 毫秒。这些似乎可以与我的实时外部测试相媲美。然而,django 开发服务器前 50% 的测试平均耗时 64 毫秒,尽管 apache 服务器的扩展性要好得多。是否有任何建议来调整 apache,以便它可以更快地进入为初始请求提供服务的范围?我不介意使用额外的服务器进行水平扩展,但请求时间对我来说意味着一切。
最佳答案
您是否考虑过使用 NGINX?它让我们在使用 uwsgi 运行时有显着的性能提升。
关于python - Django apache 与内置开发服务器的显着开销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17914360/
我试图在 (C) Python 源代码中找到内置 in 运算符的实现。我在内置函数源代码中搜索过,bltinmodule.c ,但找不到此运算符的实现。我在哪里可以找到这个实现? 我的目标是通过扩展此
我们正在开发一个 shell(学校项目)。我们不理解一种行为。为什么内置函数在重定向时不起作用? 喜欢 cd - | command 不改变目录。 或 export NAME=VALUE | comm
有人问有关如何对列表进行排序的问题。从基本List.Sort()到List.OrderBy()有几种方法。最可笑的是自己动手的SelectionSort。我迅速将其否决,但这使我思考。应用于列表的
我正在尝试使用 C 中内置的 qsort 函数对结构进行排序 typedef struct abc{ long long int fir; long long int sec; }abc; 在
我觉得有一些内置的东西。如果对象为空,我想要默认值(或者特别是 0,我只使用十进制/整数)。是否有编写此函数的内置方法? static int GetDecimalFromObject(object
Java 是否有用于生成和解析文档的内置 XML 库?如果不是,我应该使用哪个第三方? 最佳答案 Sun Java 运行时附带 Xerces 和 Xalan 实现,它们提供解析 XML(通过 DOM
我对 python 的“all”和生成器有以下问题: G = (a for a in [0,1]) all(list(G)) # returns False - as I expected 但是:
我有一些使用 gcc 内部函数的代码。我想包含代码以防缺少内在函数。我该怎么做? #ifdef __builtin_ctzll 不起作用。 最佳答案 使用最新版本的 clang,现在可以使用 __ha
人们常说应该在本地重新声明(某些)Lua 函数,因为这样可以减少开销。但这背后的确切规则/原则是什么?我怎么知道哪些功能应该完成,哪些是多余的?还是应该为每个功能完成,甚至是您自己的功能? 不幸的是,
我想实现以下功能: TestClass values 接受任意数量的 NewClass 对象 只有 NewClass 对象没有完全相同的属性值被添加到TestClass.values 我想出了这个:
我正在尝试编写一个存储过程(使用 SQL Server Management Studio 2008 R2)以从表中检索最大测量值。这似乎是一件容易的事,所以我写了一个简短的存储过程来获取 MAX。但
我刚写了我的第一个Electron应用程序。现在,我正在尝试通过electron-packager构建它。我的package.json看起来像这样: { "name": "pixelcast",
我正在寻找在 WPF 应用程序中使用的“安全”字体系列列表 - 应该安装在所有能够运行 WPF 的客户端机器上的字体系列。 Silverlight 有一个明确定义的列表( listed on MSDN
好吧,(在写了几次之后)发现System.Windows.Controls命名空间中已经有一个BooleanToVisibilityConverter,这真是一个惊喜。 可能还有更多这样隐藏的节省时间
在我的 gradle 构建文件中,我有以下插件 block plugins { `java-library` jacoco checkstyle } 这些都没有指定版本,但一切
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 3 年前。 Improve this ques
10 implementations String#reverse 已根据每个浏览器进行分析。 自 2011 年以来已对这些实现进行了解释。 当 ES6 出现时,有很多代码变得更加优雅和性能。 关于
在 Julia 包 BenchmarkTools 中,有一些像 @btime、@belapse 这样的宏对我来说似乎是多余的,因为 Julia 内置了@time、@elapse 宏。在我看来,这些宏服
我正在尝试编写一个简单的 LLVM 通行证,其目标如下: 查找所有 call指示。 在被调用函数中插入我编写的外部函数。 例如,考虑我有以下示例程序: #include #include int
我理解 'a) -> (rhs:'a -> 'a) -> 'a 在我感兴趣的情况下,我经常发现自己想要类似 (lhs:'a -> 'b) -> (rhs:'c -> 'b) -> 'b 的东西在侧面
我是一名优秀的程序员,十分优秀!