change throtle datasnapshot get

httptests
UbitUmarov 2018-01-22 19:50:07 +00:00
parent efc7480342
commit 9e4bf3439c
3 changed files with 66 additions and 8 deletions

View File

@ -713,7 +713,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
scene.Name, scene.Name,
StatType.Pull, StatType.Pull,
MeasuresOfInterest.AverageChangeOverTime, MeasuresOfInterest.AverageChangeOverTime,
stat => stat.Value = packetInbox.Count, stat => {try{stat.Value = packetInbox.Count;}catch{}},
StatVerbosity.Debug)); StatVerbosity.Debug));
// XXX: These stats are also pool stats but we register them separately since they are currently not // XXX: These stats are also pool stats but we register them separately since they are currently not

View File

@ -45,6 +45,7 @@ namespace OpenSim.Region.DataSnapshot
// private Scene m_scene = null; // private Scene m_scene = null;
private DataSnapshotManager m_externalData = null; private DataSnapshotManager m_externalData = null;
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private ExpiringCache<string, int> throotleGen = new ExpiringCache<string, int>();
public DataRequestHandler(Scene scene, DataSnapshotManager externalData) public DataRequestHandler(Scene scene, DataSnapshotManager externalData)
{ {
@ -61,25 +62,81 @@ namespace OpenSim.Region.DataSnapshot
} }
private string GetClientString(Hashtable request)
{
string clientstring = "";
if (!request.ContainsKey("headers"))
return clientstring;
Hashtable requestinfo = (Hashtable)request["headers"];
if (requestinfo.ContainsKey("x-forwarded-for"))
{
object str = requestinfo["x-forwarded-for"];
if (str != null)
{
if (!string.IsNullOrEmpty(str.ToString()))
{
return str.ToString();
}
}
}
if (!requestinfo.ContainsKey("remote_addr"))
return clientstring;
object remote_addrobj = requestinfo["remote_addr"];
if (remote_addrobj != null)
{
if (!string.IsNullOrEmpty(remote_addrobj.ToString()))
{
clientstring = remote_addrobj.ToString();
}
}
return clientstring;
}
public Hashtable OnGetSnapshot(Hashtable keysvals) public Hashtable OnGetSnapshot(Hashtable keysvals)
{ {
string snapObj = (string)keysvals["region"];
m_log.DebugFormat("[DATASNAPSHOT] Received collection request for {0}", snapObj);
Hashtable reply = new Hashtable(); Hashtable reply = new Hashtable();
int statuscode = 200; string reqtag;
string snapObj = (string)keysvals["region"];
if(string.IsNullOrWhiteSpace(snapObj))
reqtag = GetClientString(keysvals);
else
reqtag = snapObj + GetClientString(keysvals);
if(!string.IsNullOrWhiteSpace(reqtag))
{
if(throotleGen.Contains(reqtag))
{
reply["str_response_string"] = "Please try your request again later";
reply["int_response_code"] = 503;
reply["content_type"] = "text/plain";
m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
return reply;
}
throotleGen.AddOrUpdate(reqtag, 0, 60);
}
if(string.IsNullOrWhiteSpace(snapObj))
m_log.DebugFormat("[DATASNAPSHOT] Received collection request for all");
else
m_log.DebugFormat("[DATASNAPSHOT] Received collection request for {0}", snapObj);
XmlDocument response = m_externalData.GetSnapshot(snapObj); XmlDocument response = m_externalData.GetSnapshot(snapObj);
if(response == null) if(response == null)
{ {
reply["str_response_string"] = string.Empty; reply["str_response_string"] = "Please try your request again later";
reply["int_response_code"] = 503; reply["int_response_code"] = 503;
reply["content_type"] = "text"; reply["content_type"] = "text/plain";
m_log.Debug("[DATASNAPSHOT] Collection request reply try later"); m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
return reply; return reply;
} }
reply["str_response_string"] = response.OuterXml; reply["str_response_string"] = response.OuterXml;
reply["int_response_code"] = statuscode; reply["int_response_code"] = 200;
reply["content_type"] = "text/xml"; reply["content_type"] = "text/xml";
return reply; return reply;
} }

View File

@ -321,6 +321,7 @@ namespace OpenSim.Region.DataSnapshot
/** /**
* Reply to the http request * Reply to the http request
*/ */
public XmlDocument GetSnapshot(string regionName) public XmlDocument GetSnapshot(string regionName)
{ {
if(!Monitor.TryEnter(m_serializeGen,30000)) if(!Monitor.TryEnter(m_serializeGen,30000))