sentry mysql_关于Sentry(转)

博主通过实测探讨了Sentry对程序性能的影响。在内网环境下,使用UDP接口,Sentry处理普通消息和异常消息的效率较高,但当在Django应用中集成Sentry时,请求处理时间有所增加,降低了请求每秒速率。测试结果显示,Sentry的使用确实会增加服务器负载,特别是在处理异常时。
摘要由CSDN通过智能技术生成

1.4 Sentry性能

有些人担心Sentry会影响程序性能,所以我搭建了一个Sentry服务器做了下测试。

我一共使用了两台机器(机器是HP ProLLiant DL360 G4p)作为服务器, 一台安装了Sentry和Mysql, 一台安装了memcache和redis, 然后在sentry.conf.py里将QUEUE和CACHE都打开。使用supervisor启了三个服务

sentry start http

sentry start udp

sentry celeryd -B

首先测试下直接插入消息的效率如何:

from raven import Client

from timeit import timeit

try:

import cProfile as profile

except ImportError:

import profile

from pstats import Stats

client = Client('udp://11c5f6e203cb4b228b2dcac3df29dad2:55adfa2e6d8c4fd799694d8dcde372c3@172.16.97.11:9001/2')

def do_capture_msg2():

for i in range(1000):

client.captureMessage(str(i) + 'hello world! from do_capture_msg2')

def test(f, number=1000):

time = timeit(f, number=number)

st = Stats(profile.Profile().runctx('f()', globals(), locals()))

print("funcation_name msec rps tcalls funcs")

print("%-11s%6.0f%6.0f%7d%6d" % (f.__name__, 1000 * time, number / time, st.total_calls, len(st.stats)))

test(do_capture_msg2, number=10)

测试结果:

funcation_name msec rps tcalls funcs

do_capture_msg2 4093 2 287004 101

我一共提交了10000个消息,共耗时4093ms, 每次消息耗时很少,这里有两个需要注意的地方,一个是我使用的是udp接口,如果使用http接口,这个耗时会增加不少。对于udp的传输非可靠性,我认为在内网环境内应该是基本可靠的,在测试过程中,未发现消息遗漏的情况。另一个需要注意的地方是由于我的服务器性能不高,这10000个消息并不是在这4s中内就被处理完了,而是被记录到任务队列了,所以在服务器可以看到,客户端的请求完成之后,服务器的cpu使用率还需要一段时间才能降下来。

普通消息的提交处理非常快,那对于异常消息又如何:

def do_capture_exc():

try:

1 / 0

except ZeroDivisionError:

client.captureException()

test(do_capture_exc, number=1000)

测试结果:

funcation_name msec rps tcalls funcs

do_capture_exc 1061 942 1029 121

略慢,但我估计异常的抛出和捕获才是元凶

下面结合应用程序来测试性能,创建一个django程序,添加一个非常简单的view响应函数:

def sentry(request):

t = random.randint(1, 10)

time.sleep(t/1000.0)

u = User.objects.all()[0]

return HttpResponse('user %ssay hello world from django: %sms '%(u.username, t))

启动脚本是:

#!/bin/bash

gunicorn_django -k gevent -w 8 --worker-connections 3000 -b 0.0.0.0:8001 -D

ab测试结果是:

ab -n 1000 -c 100 http://172.16.97.12:8001/

Server Software: gunicorn/0.17.2

Server Hostname: 172.16.97.12

Server Port: 8001

Document Path: /sentry

Document Length: 45 bytes

Concurrency Level: 100

Time taken for tests: 2.298 seconds

Complete requests: 1000

Failed requests: 90

(Connect: 0, Receive: 0, Length: 90, Exceptions: 0)

Write errors: 0

Total transferred: 185090 bytes

HTML transferred: 45090 bytes

Requests per second: 435.11 [#/sec] (mean)

Time per request: 229.827 [ms] (mean)

Time per request: 2.298 [ms] (mean, across all concurrent requests)

Transfer rate: 78.65 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 0 0 0.7 0 9

Processing: 16 219 149.6 180 823

Waiting: 16 219 149.6 180 823

Total: 16 219 149.9 180 825

将view函数改为如下:

def sentry(request):

t = random.randint(1, 10)

time.sleep(t/1000.0)

u = User.objects.all()[0]

client.captureMessage('user %ssay hello world from django: %sms '%(u.username, t))

return HttpResponse('user %ssay hello world from django: %sms '%(u.username, t))

ab测试结果如下:

ab -n 1000 -c 100 http://172.16.97.12:8001/sentry

Server Software: gunicorn/0.17.2

Server Hostname: 172.16.97.12

Server Port: 8001

Document Path: /sentry

Document Length: 45 bytes

Concurrency Level: 100

Time taken for tests: 3.175 seconds

Complete requests: 1000

Failed requests: 90

(Connect: 0, Receive: 0, Length: 90, Exceptions: 0)

Write errors: 0

Total transferred: 185090 bytes

HTML transferred: 45090 bytes

Requests per second: 314.95 [#/sec] (mean)

Time per request: 317.510 [ms] (mean)

Time per request: 3.175 [ms] (mean, across all concurrent requests)

Transfer rate: 56.93 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 0 0 0.6 0 8

Processing: 17 301 225.2 241 1308

Waiting: 17 301 225.2 241 1307

Total: 17 302 225.5 241 1310

1000次请求运行时间从2.298s变为3.175s, rps从435.11降为314.95

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值