You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2013/08/30 18:20:51 UTC
[38/50] git commit: TS-2156: Fix stats trap in different type of
threads
TS-2156: Fix stats trap in different type of threads
There are two ways to create threads in ATS:
1) By EventProcessor::spawn_event_threads(), such as ET_NET threads.
2) By EventProcessor::spawn_thread(), such as flush thread.
But I found that we can't stats the same things across these two type of
threads.
This patch will make stats in both type of threads transparent for upper
layer developers.
BTW: renames "dthreads" to "all_dthreads" to keep naming consistency with
"all_ethreads".
Signed-off-by: Yunkai Zhang <qi...@taobao.com>
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/fb20be52
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/fb20be52
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/fb20be52
Branch: refs/heads/5.0.x
Commit: fb20be5250272d010503a0a642d7f1deaa17d065
Parents: 4633563
Author: Yunkai Zhang <qi...@taobao.com>
Authored: Mon Aug 26 15:24:37 2013 +0800
Committer: Yunkai Zhang <qi...@taobao.com>
Committed: Tue Aug 27 14:33:13 2013 +0800
----------------------------------------------------------------------
CHANGES | 2 ++
iocore/eventsystem/I_EventProcessor.h | 2 +-
iocore/eventsystem/P_UnixEventProcessor.h | 2 +-
iocore/eventsystem/UnixEventProcessor.cc | 6 ++---
lib/records/RecProcess.cc | 33 ++++++++++++++++++++++++++
proxy/StatSystem.h | 8 +++++++
6 files changed, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fb20be52/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index f249ab1..c71119d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
Changes with Apache Traffic Server 4.1.0
+ *) [TS-2156] Fix stats trap in different type of threads
+
*) [TS-2160] Remove ats_is_ip_nonroutable and replace it with the less confusing
ats_is_ip_linklocal and ats_is_ip_private.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fb20be52/iocore/eventsystem/I_EventProcessor.h
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/I_EventProcessor.h b/iocore/eventsystem/I_EventProcessor.h
index cf2f796..40d8e94 100644
--- a/iocore/eventsystem/I_EventProcessor.h
+++ b/iocore/eventsystem/I_EventProcessor.h
@@ -314,7 +314,7 @@ public:
Event * schedule(Event * e, EventType etype, bool fast_signal = false);
EThread *assign_thread(EventType etype);
- EThread *dthreads[MAX_EVENT_THREADS];
+ EThread *all_dthreads[MAX_EVENT_THREADS];
int n_dthreads; // No. of dedicated threads
volatile int thread_data_used;
};
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fb20be52/iocore/eventsystem/P_UnixEventProcessor.h
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/P_UnixEventProcessor.h b/iocore/eventsystem/P_UnixEventProcessor.h
index 7249770..d9a1e73 100644
--- a/iocore/eventsystem/P_UnixEventProcessor.h
+++ b/iocore/eventsystem/P_UnixEventProcessor.h
@@ -36,7 +36,7 @@ n_dthreads(0),
thread_data_used(0)
{
memset(all_ethreads, 0, sizeof(all_ethreads));
- memset(dthreads, 0, sizeof(dthreads));
+ memset(all_dthreads, 0, sizeof(all_dthreads));
memset(n_threads_for_type, 0, sizeof(n_threads_for_type));
memset(next_thread_for_type, 0, sizeof(next_thread_for_type));
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fb20be52/iocore/eventsystem/UnixEventProcessor.cc
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/UnixEventProcessor.cc b/iocore/eventsystem/UnixEventProcessor.cc
index 776eb64..29f730a 100644
--- a/iocore/eventsystem/UnixEventProcessor.cc
+++ b/iocore/eventsystem/UnixEventProcessor.cc
@@ -223,9 +223,9 @@ EventProcessor::spawn_thread(Continuation *cont, const char* thr_name, size_t st
Event *e = eventAllocator.alloc();
e->init(cont, 0, 0);
- dthreads[n_dthreads] = NEW(new EThread(DEDICATED, e, sem));
- e->ethread = dthreads[n_dthreads];
- e->mutex = e->continuation->mutex = dthreads[n_dthreads]->mutex;
+ all_dthreads[n_dthreads] = NEW(new EThread(DEDICATED, e, sem));
+ e->ethread = all_dthreads[n_dthreads];
+ e->mutex = e->continuation->mutex = all_dthreads[n_dthreads]->mutex;
n_dthreads++;
e->ethread->start(thr_name, stacksize);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fb20be52/lib/records/RecProcess.cc
----------------------------------------------------------------------
diff --git a/lib/records/RecProcess.cc b/lib/records/RecProcess.cc
index 3f1f34e..f5606cc 100644
--- a/lib/records/RecProcess.cc
+++ b/lib/records/RecProcess.cc
@@ -117,6 +117,13 @@ raw_stat_get_total(RecRawStatBlock *rsb, int id, RecRawStat *total)
total->sum += tlp->sum;
total->count += tlp->count;
}
+
+ for (i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ total->sum += tlp->sum;
+ total->count += tlp->count;
+ }
+
if (total->sum < 0) { // Assure that we stay positive
total->sum = 0;
}
@@ -144,6 +151,13 @@ raw_stat_sync_to_global(RecRawStatBlock *rsb, int id)
total.sum += tlp->sum;
total.count += tlp->count;
}
+
+ for (i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ total.sum += tlp->sum;
+ total.count += tlp->count;
+ }
+
if (total.sum < 0) { // Assure that we stay positive
total.sum = 0;
}
@@ -198,6 +212,13 @@ raw_stat_clear(RecRawStatBlock *rsb, int id)
ink_atomic_swap(&(tlp->sum), (int64_t)0);
ink_atomic_swap(&(tlp->count), (int64_t)0);
}
+
+ for (int i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ ink_atomic_swap(&(tlp->sum), (int64_t)0);
+ ink_atomic_swap(&(tlp->count), (int64_t)0);
+ }
+
return REC_ERR_OKAY;
}
@@ -223,6 +244,12 @@ raw_stat_clear_sum(RecRawStatBlock *rsb, int id)
tlp = ((RecRawStat *) ((char *) (eventProcessor.all_ethreads[i]) + rsb->ethr_stat_offset)) + id;
ink_atomic_swap(&(tlp->sum), (int64_t)0);
}
+
+ for (int i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ ink_atomic_swap(&(tlp->sum), (int64_t)0);
+ }
+
return REC_ERR_OKAY;
}
@@ -248,6 +275,12 @@ raw_stat_clear_count(RecRawStatBlock *rsb, int id)
tlp = ((RecRawStat *) ((char *) (eventProcessor.all_ethreads[i]) + rsb->ethr_stat_offset)) + id;
ink_atomic_swap(&(tlp->count), (int64_t)0);
}
+
+ for (int i = 0; i < eventProcessor.n_dthreads; i++) {
+ tlp = ((RecRawStat *) ((char *) (eventProcessor.all_dthreads[i]) + rsb->ethr_stat_offset)) + id;
+ ink_atomic_swap(&(tlp->count), (int64_t)0);
+ }
+
return REC_ERR_OKAY;
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fb20be52/proxy/StatSystem.h
----------------------------------------------------------------------
diff --git a/proxy/StatSystem.h b/proxy/StatSystem.h
index 6d56797..32128ab 100644
--- a/proxy/StatSystem.h
+++ b/proxy/StatSystem.h
@@ -410,6 +410,10 @@ global_dyn_stats[X].sum = 0
_s.count += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].count; \
_s.sum += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].sum; \
} \
+ for (int _e = 0; _e < eventProcessor.n_dthreads ; _e++) { \
+ _s.count += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].count; \
+ _s.sum += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].sum; \
+ } \
C = _s.count; \
S = _s.sum; \
} while (0)
@@ -418,6 +422,8 @@ global_dyn_stats[X].sum = 0
ink_statval_t _s = global_dyn_stats[X].count; \
for (int _e = 0; _e < eventProcessor.n_ethreads ; _e++) \
_s += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].count; \
+ for (int _e = 0; _e < eventProcessor.n_dthreads ; _e++) \
+ _s += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].count; \
C = _s; \
} while (0)
@@ -425,6 +431,8 @@ global_dyn_stats[X].sum = 0
ink_statval_t _s = global_dyn_stats[X].sum; \
for (int _e = 0; _e < eventProcessor.n_ethreads ; _e++) \
_s += eventProcessor.all_ethreads[_e]->global_dyn_stats[X].sum; \
+ for (int _e = 0; _e < eventProcessor.n_dthreads ; _e++) \
+ _s += eventProcessor.all_dthreads[_e]->global_dyn_stats[X].sum; \
S = _s; \
} while (0)