Thank you kindly, RemedyTomm for a patch that:

Following feedback from 0003440, i've made some changes to the new texture pipeline to optimise
 performance. The changes are:
 - Fixed a math issue where a small percentage of images with a certain size (on the packet boundary) would not have their final data delivered. This issue has been present since pre- 0003440
 - It was suggested that a discardlevel of -1 and a prioriy of 0 meant to abandon the transfer, this is incorrect and caused some textures to clog.
 - The texture throttle blocking queue is now only filled in relation to the actual throttle amount.. i.e, on a connection throttled to 300k, only twenty packets will be placed in the queue at a time, on a larger connection it will be much more. This is to balance responsiveness to requests and speed, and to minimise wasted packets.
 - The engine now keeps track of the number of pending textures, and the stack will not be walked if there's no textures pending, saving CPU. Textures are only considered "pending" when they've already been decoded.
 - As part of the above, some textures may receive twice as much data per cycle if the number of pending textures is below the cycle threshold, this should prevent loading from slowing down when there are fewer textures in the queue.
0.6.5-rc1
Charles Krinke 2009-04-18 18:35:03 +00:00
parent 47d6dee657
commit 2578db3dfa
3 changed files with 134 additions and 58 deletions

View File

@ -48,6 +48,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public class J2KImage
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public double m_designatedPriorityKey;
public double m_requestedPriority = 0.0d;
@ -72,7 +73,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private const int cImagePacketSize = 1000;
private const int cFirstPacketSize = 600;
private AssetBase m_asset = null;
private LLImageManager m_image;
public J2KImage(LLImageManager image)
{
m_image = image;
}
public uint m_pPacketNumber
{
@ -103,6 +108,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public void J2KDecodedCallback(UUID AssetId, OpenJPEG.J2KLayerInfo[] layers)
{
m_image.m_outstandingtextures++;
Layers = layers;
m_decoded = true;
RunUpdate();
@ -130,8 +136,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
if (m_packetNumber == 1)
return m_asset.Data.Length;
return (m_asset.Data.Length - cFirstPacketSize) % cImagePacketSize;
int lastsize = (m_asset.Data.Length - cFirstPacketSize) % cImagePacketSize;
//If the last packet size is zero, it's really cImagePacketSize, it sits on the boundary
if (lastsize == 0)
{
lastsize = cImagePacketSize;
}
return lastsize;
}
public int CurrentBytePosition()
{
@ -247,7 +260,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_sentinfo = true;
m_packetNumber++;
}
bool ignoreStop = false;
if (m_packetNumber < 2)
{
m_packetNumber = 2;
@ -260,6 +273,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
SendMore = SendPacket(client);
m_packetNumber++;
}
if (m_packetNumber > m_stopPacket)
{
@ -344,6 +358,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (Layers.Length > 0)
{
m_stopPacket = (uint)GetPacketForBytePosition(Layers[(Layers.Length - 1) - m_discardLevel].End);
//I don't know why, but the viewer seems to expect the final packet if the file
//is just one packet bigger.
if (TexturePacketCount() == m_stopPacket + 1)
{
m_stopPacket = TexturePacketCount();
}
}
else
{

View File

@ -47,6 +47,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
//Close
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private bool m_shuttingdown = false;
private long m_lastloopprocessed = 0;
private LLClientView m_client; //Client we're assigned to
private IAssetCache m_assetCache; //Asset Cache
@ -58,6 +59,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private Dictionary<int, int> m_priorityresolver; //Enabling super fast assignment of images with the same priorities
private const double doubleMinimum = .0000001;
public int m_outstandingtextures = 0;
//Constructor
public LLImageManager(LLClientView client, IAssetCache pAssetCache, IJ2KDecoder pJ2kDecodeModule)
{
@ -92,20 +95,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
J2KImage imgrequest = m_imagestore[newRequest.RequestedAssetID];
//if (newRequest.requestSequence > imgrequest.m_lastSequence)
//{
if (newRequest.requestSequence > imgrequest.m_lastSequence)
{
imgrequest.m_lastSequence = newRequest.requestSequence;
//First of all, is this being killed?
if (newRequest.Priority == 0.0f && newRequest.DiscardLevel == -1)
{
//Remove the old priority
m_priorities.Remove(imgrequest.m_designatedPriorityKey);
m_imagestore.Remove(imgrequest.m_requestedUUID);
imgrequest = null;
}
else
{
//if (newRequest.Priority == 0.0f && newRequest.DiscardLevel == -1)
//{
//Do nothing (leaving the if for future use)
//}
//else
//{
//Check the priority
@ -125,14 +125,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
//Update the requested packet number
imgrequest.m_requestedPacketNumber = newRequest.PacketNumber;
//Check if this will create an outstanding texture request
bool activated = imgrequest.m_completedSendAtCurrentDiscardLevel;
//Run an update
imgrequest.RunUpdate();
if (activated && !imgrequest.m_completedSendAtCurrentDiscardLevel && imgrequest.m_decoded)
{
m_outstandingtextures++;
}
//}
}
}
else
{
J2KImage imgrequest = new J2KImage();
J2KImage imgrequest = new J2KImage(this);
//Assign our missing substitute
imgrequest.m_MissingSubstitute = m_missingsubstitute;
@ -198,9 +205,33 @@ namespace OpenSim.Region.ClientStack.LindenUDP
//since we're processing in a more efficient manner.
int numCollected = 0;
//First of all make sure our packet queue isn't above our threshold
if (m_client == null)
return;
//Calculate our threshold
int threshold;
if (m_lastloopprocessed == 0)
{
//This is decent for a semi fast machine, but we'll calculate it more accurately based on time below
threshold = m_client.PacketHandler.PacketQueue.TextureThrottle.Current / 6300;
m_lastloopprocessed = DateTime.Now.Ticks;
}
else
{
double throttleseconds = ((double)DateTime.Now.Ticks - (double)m_lastloopprocessed) / (double)TimeSpan.TicksPerSecond;
throttleseconds = throttleseconds * m_client.PacketHandler.PacketQueue.TextureThrottle.Current;
//Average of 1000 bytes per packet
throttleseconds = throttleseconds / 1000;
//Safe-zone multiplier of 2.0
threshold = (int)(throttleseconds * 2.0);
m_lastloopprocessed = DateTime.Now.Ticks;
}
if (threshold < 10)
{
threshold = 10;
}
if (m_client.PacketHandler == null)
return;
@ -208,9 +239,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (m_client.PacketHandler.PacketQueue == null)
return;
//First of all make sure our packet queue isn't above our threshold
if (m_client.PacketHandler.PacketQueue.TextureOutgoingPacketQueueCount < 200)
//Uncomment this to see what the texture stack is doing
//m_log.Debug("Queue: " + m_client.PacketHandler.PacketQueue.TextureOutgoingPacketQueueCount.ToString() + " Threshold: " + threshold.ToString() + " outstanding: " + m_outstandingtextures.ToString());
if (m_client.PacketHandler.PacketQueue.TextureOutgoingPacketQueueCount < threshold && m_outstandingtextures > 0)
{
bool justreset = false;
for (int x = m_priorities.Count - 1; x > -1; x--)
{
@ -221,11 +258,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
numCollected++;
//SendPackets will send up to ten packets per cycle
//m_log.Debug("Processing packet with priority of " + imagereq.m_designatedPriorityKey.ToString());
if (imagereq.SendPackets(m_client))
{
//Send complete
if (!imagereq.m_completedSendAtCurrentDiscardLevel)
{
imagereq.m_completedSendAtCurrentDiscardLevel = true;
m_outstandingtextures--;
//Re-assign priority to bottom
//Remove the old priority
m_priorities.Remove(imagereq.m_designatedPriorityKey);
@ -250,12 +289,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_priorityresolver.Add((int)lowest, 0);
}
}
//m_log.Debug("...now has priority of " + imagereq.m_designatedPriorityKey.ToString());
}
if (numCollected == count)
{
break;
}
}
if (numCollected == count || m_outstandingtextures == 0)
break;
if (numCollected % m_outstandingtextures == 0 && !justreset)
{
//We've gotten as much as we can from the stack,
//reset to the top so that we can send MOAR DATA (nomnomnom)!
x = m_priorities.Count - 1;
justreset = true; //prevents us from getting stuck in a loop
}
}
}

View File

@ -51,6 +51,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
get { return m_minAllowableThrottle; }
}
public int Current
{
get { return m_currentThrottle; }
}
/// <summary>
/// Constructor.
/// </summary>