7 SMTP_HOST
= 'localhost'
10 MSG_COUNT
= 100 #Messages to Send per Test
11 CONN_COUNT
= 20 #Messages to send on Connection test, beware it could be slow
12 THREAD_COUNT
= [2, 5, 10]
14 MSG_FROM
= 'testmail@mymail.com'
15 MSG_TO
= 'testuser@localhost'
16 MSG_DATA
= str().zfill(MSG_SIZE
)
19 print 'Benchmarking Single Session'
21 #Initialize Measuring Variables
25 server
= smtplib
.SMTP(SMTP_HOST
, SMTP_PORT
)
28 for i
in xrange(MSG_COUNT
):
29 time_start
= time
.time()
30 server
.sendmail(MSG_FROM
, MSG_TO
, MSG_DATA
)
31 time_end
= time
.time()
32 total_time
+= time_end
- time_start
34 #Disconnect from Server
37 #Calculate Avg time per msg and Messages Per Second
38 msg_avg
= total_time
/ MSG_COUNT
41 print ' * Total time:', total_time
42 print ' * Avg. Time per message:', msg_avg
43 print ' * Messages Per second:', mps
44 print ' * Total Message Data Transmitted:', MSG_SIZE
* MSG_COUNT
, 'bytes'
45 print ' * Data Rate:', (MSG_SIZE
* MSG_COUNT
) / total_time
, 'bytes/second'
47 def ConnectionBench():
48 print 'Benchmarking Connection Speed'
49 print ' - Connection Count:', CONN_COUNT
50 #Initialize Measuring Variables
54 for i
in xrange(CONN_COUNT
):
55 time_start
= time
.time()
57 server
= smtplib
.SMTP(SMTP_HOST
, SMTP_PORT
)
58 server
.sendmail(MSG_FROM
, MSG_TO
, MSG_DATA
)
60 time_end
= time
.time()
61 total_time
+= time_end
- time_start
63 #Calculate Avg time per msg and Messages Per Second
64 msg_avg
= total_time
/ CONN_COUNT
67 print ' * Total time:', total_time
68 print ' * Avg. Time per message:', msg_avg
69 print ' * Messages Per second:', mps
70 print ' * Total Message Data Transmitted:', MSG_SIZE
* CONN_COUNT
, 'bytes'
71 print ' * Data Rate:', (MSG_SIZE
* CONN_COUNT
) / total_time
, 'bytes/second'
73 class ThreadBench(threading
.Thread
):
74 def __init__(self
, msgcount
):
75 threading
.Thread
.__init
__(self
)
76 self
.msgcount
= msgcount
78 conn
= smtplib
.SMTP(SMTP_HOST
, SMTP_PORT
)
80 for i
in xrange(self
.msgcount
):
81 time_start
= time
.time()
82 conn
.sendmail(MSG_FROM
, MSG_TO
, MSG_DATA
);
83 time_end
= time
.time()
84 self
.total_time
+= time_end
- time_start
86 self
.msg_avg
= self
.total_time
/ self
.msgcount
87 self
.mps
= 1.0 / self
.msg_avg
89 def ThreadBenchmark(thread_count
):
90 print 'Benchmarking Multiple Sessions (Threaded)'
91 print ' - Thread Count:', thread_count
94 thread_msgcount
= int(MSG_COUNT
/ thread_count
)
96 print ' - Per Thread Message Count:', thread_msgcount
97 print ' - Total Message Count:', thread_msgcount
* thread_count
99 for i
in xrange(thread_count
):
100 threads
.append(ThreadBench(thread_msgcount
))
102 time_start
= time
.time()
107 time_end
= time
.time()
109 total_time
= time_end
- time_start
115 accum_time
+= t
.total_time
118 avg_mps
= avg_mps
/ thread_count
119 avg_msg
= avg_msg
/ thread_count
120 mps
= (thread_msgcount
* thread_count
) / total_time
122 total_data
= (thread_msgcount
* thread_count
) * MSG_SIZE
123 print ' * Total Time:', total_time
124 print ' * Accumulated Time:', accum_time
125 print ' * TT/AT Ratio:', total_time
/ accum_time
126 print ' * Time per Message:', msg_time
127 print ' * Messages per Second:', mps
128 print ' * Avg. Thread Time per Message:', avg_msg
129 print ' * Avg. Thread Message per Second:', avg_mps
130 print ' * Total Message Data Transmited:', total_data
, 'bytes'
131 print ' * Data Rate:', total_data
/ total_time
, 'bytes/second'
132 print ' * Per Thread Data:'
133 for i
in xrange(thread_count
):
136 print ' * Total Time:', t
.total_time
137 print ' * Avg. Time per message:', t
.msg_avg
138 print ' * Messages per Second:', t
.mps
140 print 'FancyMail Simple SMTP Benchmark Suite'
142 print ' * SMTP Port:', SMTP_PORT
143 print ' * SMTP Host:', SMTP_HOST
144 print ' * Message Count:', MSG_COUNT
145 print ' * Message Size:', MSG_SIZE
157 for i
in THREAD_COUNT
: