Skip to content

Commit

Permalink
HHQ6059 : Solution for problem : measurement handler is eating 90% of…
Browse files Browse the repository at this point in the history
… the cpu
  • Loading branch information
Irena Goverdovsky committed Oct 7, 2015
1 parent aed1015 commit 7e974be
Show file tree
Hide file tree
Showing 13 changed files with 956 additions and 630 deletions.
Expand Up @@ -29,7 +29,9 @@

public class AgentCallbackClientException extends NestedException {

public AgentCallbackClientException () {
public final static String PERMISSION_DENIED_ERROR_MSG = "Permission denied";

public AgentCallbackClientException () {
super();
}

Expand Down
Expand Up @@ -48,7 +48,7 @@ public MeasurementCallbackClient(ProviderFetcher fetcher){
/**
* Returns the current server time
*/
public long measurementSendReport(MeasurementReport report)
public long measurementSendReport(MeasurementReport report, boolean closeConn)
throws AgentCallbackClientException
{
MeasurementSendReport_args args;
Expand All @@ -62,7 +62,7 @@ public long measurementSendReport(MeasurementReport report)
res = (MeasurementSendReport_result)
this.invokeLatherCall(provider,
CommandInfo.CMD_MEASUREMENT_SEND_REPORT,
args);
args, closeConn);

try {
return res.getTime();
Expand Down
Expand Up @@ -102,6 +102,8 @@ public class MeasurementCommandsServer

private CollectorThread collectorThread;

private SchedulerOffsetManager schedulerOffsetManager;

public MeasurementCommandsServer(){
this.verAPI = new MeasurementCommandsAPI();
this.scheduleThread = null;
Expand Down Expand Up @@ -251,8 +253,12 @@ public void startup(AgentDaemon agent)
e.getMessage());
}

this.senderObject = new SenderThread(this.bootConfig.getBootProperties(),
this.storage, this.schedStorage);
this.schedulerOffsetManager = new SchedulerOffsetManager(this.storage);

this.senderObject = new SenderThread(this.bootConfig,
this.storage, this.schedStorage,
this.bootConfig.getBootProperties(),
this.schedulerOffsetManager);

this.scheduleObject = new ScheduleThread(this.senderObject,
this.pluginManager,
Expand Down
Expand Up @@ -259,8 +259,8 @@ public void run() {
ParsedTemplate pt = getParsedTemplate(mt.meas);
if (pt.metric.isAvail()) {
MetricValue data = new MetricValue(MeasurementConstants.AVAIL_DOWN);
sender.processData(mt.meas.getDsnID(), data,
mt.meas.getDerivedID(), true);
sender.processData(mt.meas.getDsnID(), data, mt.meas.getInterval(),
mt.meas.getDerivedID(), true);
}
// Task will be removed on next iteration
}
Expand Down Expand Up @@ -658,7 +658,7 @@ else if (data.isFuture()) {
return;
}

sender.processData(meas.getDsnID(), data, meas.getDerivedID(), MeasurementConstants.CAT_AVAILABILITY.equals(category));
sender.processData(meas.getDsnID(), data, meas.getInterval() ,meas.getDerivedID(), MeasurementConstants.CAT_AVAILABILITY.equals(category));
synchronized (statsLock) {
statNumMetricsFetched++;
}
Expand Down Expand Up @@ -850,6 +850,7 @@ private long collect() {
}

if (schedules != null) {
sender.ensureSyncedToServerTime();
for (Iterator<ResourceSchedule> it = schedules.values().iterator(); it.hasNext() && (!shouldDie.get());) {
ResourceSchedule rs = it.next();
try {
Expand Down
@@ -0,0 +1,38 @@
package org.hyperic.hq.measurement.agent.server;

import java.util.Random;

import org.hyperic.hq.agent.server.AgentStorageProvider;
import org.hyperic.util.TimeUtil;

public class SchedulerOffsetManager {

private static final String PROP_SCHEDULER_OFFSET_SEED = "agent.scheduler.offset.seed";

private long offsetSeed;

public SchedulerOffsetManager(AgentStorageProvider storage) {
offsetSeed = getSchedulerOffsetSeed(storage);
}

private long getSchedulerOffsetSeed(AgentStorageProvider storage) {
String offsetSeedString = storage.getValue(PROP_SCHEDULER_OFFSET_SEED);
long offsetSeed;
if (offsetSeedString != null) {
offsetSeed = Long.parseLong(offsetSeedString);
} else {
Random rand = new Random();
offsetSeed = Math.abs(rand.nextLong());
storage.setValue(PROP_SCHEDULER_OFFSET_SEED, Long.toString(offsetSeed));
}
return offsetSeed;
}

public long getSchedluerOffsetForInterval(long interval) {
long offset = offsetSeed % interval;
// Round offset to the nearest minute
offset -= (offset % TimeUtil.MILLIS_IN_MINUTE);
return offset;
}

}
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.hyperic.hq.measurement.agent.server;

import org.apache.commons.lang.builder.ToStringBuilder;

public class SendBatchResult {

public enum StatusBatchResult {
SUCCESS_ALL, ERROR_ALL, SUCCESS_BATCH, ERROR_BATCH
}

private long timeStamp = 0; // in milliseconds
private StatusBatchResult status;

public SendBatchResult(StatusBatchResult status, long timeStamp) {
this.timeStamp = timeStamp;
this.status = status;
}

public SendBatchResult(StatusBatchResult status) {
this.status = status;
}

public long getTimeStamp() {
return timeStamp;
}

public StatusBatchResult getStatus() {
return status;
}

public boolean isDone() {
return StatusBatchResult.ERROR_ALL.equals(status)
|| StatusBatchResult.SUCCESS_ALL.equals(status);

}

@Override
public String toString() {
return new ToStringBuilder(this).append("Status", status.toString())
.append("Timestamp", timeStamp).toString();

}

}
Expand Up @@ -30,6 +30,7 @@

public interface Sender {

public void processData(int dsnId, MetricValue data, int derivedID, boolean isAvail);
void processData(long dsnId, MetricValue data, long samplingInterval ,long derivedID, boolean isAvail);

void ensureSyncedToServerTime();
}

0 comments on commit 7e974be

Please sign in to comment.