diff options
Diffstat (limited to 'OpenSim/Region')
3 files changed, 153 insertions, 52 deletions
diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 53b8ebc..c520356 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs | |||
@@ -129,18 +129,18 @@ namespace Flotsam.RegionModules.AssetCache | |||
129 | if (name == Name) | 129 | if (name == Name) |
130 | { | 130 | { |
131 | m_Enabled = true; | 131 | m_Enabled = true; |
132 | m_log.InfoFormat("[ASSET CACHE]: {0} enabled", this.Name); | 132 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} enabled", this.Name); |
133 | 133 | ||
134 | IConfig assetConfig = source.Configs["AssetCache"]; | 134 | IConfig assetConfig = source.Configs["AssetCache"]; |
135 | if (assetConfig == null) | 135 | if (assetConfig == null) |
136 | { | 136 | { |
137 | m_log.Warn("[ASSET CACHE]: AssetCache missing from OpenSim.ini, using defaults."); | 137 | m_log.Warn("[FLOTSAM ASSET CACHE]: AssetCache missing from OpenSim.ini, using defaults."); |
138 | m_log.InfoFormat("[ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); | 138 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); |
139 | return; | 139 | return; |
140 | } | 140 | } |
141 | 141 | ||
142 | m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory); | 142 | m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory); |
143 | m_log.InfoFormat("[ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); | 143 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory", m_DefaultCacheDirectory); |
144 | 144 | ||
145 | m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", true); | 145 | m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", true); |
146 | m_MemoryExpiration = TimeSpan.FromHours(assetConfig.GetDouble("MemoryCacheTimeout", m_DefaultMemoryExpiration)); | 146 | m_MemoryExpiration = TimeSpan.FromHours(assetConfig.GetDouble("MemoryCacheTimeout", m_DefaultMemoryExpiration)); |
@@ -188,6 +188,8 @@ namespace Flotsam.RegionModules.AssetCache | |||
188 | } | 188 | } |
189 | 189 | ||
190 | m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000); | 190 | m_CacheWarnAt = assetConfig.GetInt("CacheWarnAt", 30000); |
191 | |||
192 | |||
191 | } | 193 | } |
192 | } | 194 | } |
193 | } | 195 | } |
@@ -203,7 +205,14 @@ namespace Flotsam.RegionModules.AssetCache | |||
203 | public void AddRegion(Scene scene) | 205 | public void AddRegion(Scene scene) |
204 | { | 206 | { |
205 | if (m_Enabled) | 207 | if (m_Enabled) |
208 | { | ||
206 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); | 209 | scene.RegisterModuleInterface<IImprovedAssetCache>(this); |
210 | |||
211 | //scene.AddCommand(this, "flotsamcache", "", "Display a list of console commands for the Flotsam Asset Cache", HandleConsoleCommand); | ||
212 | scene.AddCommand(this, "flotsamcache counts", "flotsamcache counts", "Display the number of cached assets", HandleConsoleCommand); | ||
213 | scene.AddCommand(this, "flotsamcache clearmem", "flotsamcache clearmem", "Remove all assets cached in memory", HandleConsoleCommand); | ||
214 | scene.AddCommand(this, "flotsamcache clearfile", "flotsamcache clearfile", "Remove all assets cached on disk", HandleConsoleCommand); | ||
215 | } | ||
207 | } | 216 | } |
208 | 217 | ||
209 | public void RemoveRegion(Scene scene) | 218 | public void RemoveRegion(Scene scene) |
@@ -365,16 +374,16 @@ namespace Flotsam.RegionModules.AssetCache | |||
365 | { | 374 | { |
366 | m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0; | 375 | m_HitRateFile = (double)m_DiskHits / m_Requests * 100.0; |
367 | 376 | ||
368 | m_log.InfoFormat("[ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); | 377 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit"); |
369 | m_log.InfoFormat("[ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests); | 378 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Hit Rate {0}% for {1} requests", m_HitRateFile.ToString("0.00"), m_Requests); |
370 | 379 | ||
371 | if (m_MemoryCacheEnabled) | 380 | if (m_MemoryCacheEnabled) |
372 | { | 381 | { |
373 | m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0; | 382 | m_HitRateMemory = (double)m_MemoryHits / m_Requests * 100.0; |
374 | m_log.InfoFormat("[ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests); | 383 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Hit Rate {0}% for {1} requests", m_HitRateMemory.ToString("0.00"), m_Requests); |
375 | } | 384 | } |
376 | 385 | ||
377 | m_log.InfoFormat("[ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress); | 386 | m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} unnessesary requests due to requests for assets that are currently downloading.", m_RequestsForInprogress); |
378 | 387 | ||
379 | } | 388 | } |
380 | 389 | ||
@@ -384,7 +393,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
384 | public void Expire(string id) | 393 | public void Expire(string id) |
385 | { | 394 | { |
386 | if (m_LogLevel >= 2) | 395 | if (m_LogLevel >= 2) |
387 | m_log.DebugFormat("[ASSET CACHE]: Expiring Asset {0}.", id); | 396 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Expiring Asset {0}.", id); |
388 | 397 | ||
389 | try | 398 | try |
390 | { | 399 | { |
@@ -406,7 +415,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
406 | public void Clear() | 415 | public void Clear() |
407 | { | 416 | { |
408 | if (m_LogLevel >= 2) | 417 | if (m_LogLevel >= 2) |
409 | m_log.Debug("[ASSET CACHE]: Clearing Cache."); | 418 | m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing Cache."); |
410 | 419 | ||
411 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | 420 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) |
412 | { | 421 | { |
@@ -420,29 +429,42 @@ namespace Flotsam.RegionModules.AssetCache | |||
420 | private void CleanupExpiredFiles(object source, ElapsedEventArgs e) | 429 | private void CleanupExpiredFiles(object source, ElapsedEventArgs e) |
421 | { | 430 | { |
422 | if (m_LogLevel >= 2) | 431 | if (m_LogLevel >= 2) |
423 | m_log.DebugFormat("[ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration.ToString()); | 432 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Checking for expired files older then {0}.", m_FileExpiration.ToString()); |
424 | 433 | ||
425 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | 434 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) |
426 | { | 435 | { |
427 | foreach (string file in Directory.GetFiles(dir)) | 436 | CleanExpiredFiles(dir); |
428 | { | 437 | } |
429 | if (DateTime.Now - File.GetLastAccessTime(file) > m_FileExpiration) | 438 | } |
430 | { | ||
431 | File.Delete(file); | ||
432 | } | ||
433 | } | ||
434 | 439 | ||
435 | int dirSize = Directory.GetFiles(dir).Length; | 440 | /// <summary> |
436 | if (dirSize == 0) | 441 | /// Recurses through specified directory checking for expired asset files and deletes them. Also removes empty directories. |
437 | { | 442 | /// </summary> |
438 | Directory.Delete(dir); | 443 | /// <param name="dir"></param> |
439 | } | 444 | private void CleanExpiredFiles(string dir) |
440 | else if (dirSize >= m_CacheWarnAt) | 445 | { |
446 | foreach (string file in Directory.GetFiles(dir)) | ||
447 | { | ||
448 | if (DateTime.Now - File.GetLastAccessTime(file) > m_FileExpiration) | ||
441 | { | 449 | { |
442 | m_log.WarnFormat("[ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", dir, dirSize); | 450 | File.Delete(file); |
443 | } | 451 | } |
444 | |||
445 | } | 452 | } |
453 | |||
454 | foreach (string subdir in Directory.GetDirectories(dir)) | ||
455 | { | ||
456 | CleanExpiredFiles(subdir); | ||
457 | } | ||
458 | |||
459 | int dirSize = Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length; | ||
460 | if (dirSize == 0) | ||
461 | { | ||
462 | Directory.Delete(dir); | ||
463 | } | ||
464 | else if (dirSize >= m_CacheWarnAt) | ||
465 | { | ||
466 | m_log.WarnFormat("[FLOTSAM ASSET CACHE]: Cache folder exceeded CacheWarnAt limit {0} {1}. Suggest increasing tiers, tier length, or reducing cache expiration", dir, dirSize); | ||
467 | } | ||
446 | } | 468 | } |
447 | 469 | ||
448 | private string GetFileName(string id) | 470 | private string GetFileName(string id) |
@@ -486,7 +508,7 @@ namespace Flotsam.RegionModules.AssetCache | |||
486 | File.Move(tempname, filename); | 508 | File.Move(tempname, filename); |
487 | 509 | ||
488 | if (m_LogLevel >= 2) | 510 | if (m_LogLevel >= 2) |
489 | m_log.DebugFormat("[ASSET CACHE]: Cache Stored :: {0}", asset.ID); | 511 | m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Cache Stored :: {0}", asset.ID); |
490 | } | 512 | } |
491 | catch (Exception e) | 513 | catch (Exception e) |
492 | { | 514 | { |
@@ -522,8 +544,88 @@ namespace Flotsam.RegionModules.AssetCache | |||
522 | string[] text = e.ToString().Split(new char[] { '\n' }); | 544 | string[] text = e.ToString().Split(new char[] { '\n' }); |
523 | foreach (string t in text) | 545 | foreach (string t in text) |
524 | { | 546 | { |
525 | m_log.ErrorFormat("[ASSET CACHE]: {0} ", t); | 547 | m_log.ErrorFormat("[FLOTSAM ASSET CACHE]: {0} ", t); |
548 | } | ||
549 | } | ||
550 | |||
551 | private int GetFileCacheCount(string dir) | ||
552 | { | ||
553 | int count = Directory.GetFiles(dir).Length; | ||
554 | |||
555 | foreach (string subdir in Directory.GetDirectories(dir)) | ||
556 | { | ||
557 | count += GetFileCacheCount(subdir); | ||
526 | } | 558 | } |
559 | |||
560 | return count; | ||
527 | } | 561 | } |
562 | |||
563 | #region Console Commands | ||
564 | private void HandleConsoleCommand(string module, string[] cmdparams) | ||
565 | { | ||
566 | if (cmdparams.Length == 2) | ||
567 | { | ||
568 | string cmd = cmdparams[1]; | ||
569 | switch (cmd) | ||
570 | { | ||
571 | case "count": | ||
572 | case "counts": | ||
573 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache : {0}", m_MemoryCache.Count); | ||
574 | |||
575 | int fileCount = GetFileCacheCount(m_CacheDirectory); | ||
576 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] File Cache : {0}", fileCount); | ||
577 | |||
578 | break; | ||
579 | |||
580 | case "clearmem": | ||
581 | m_MemoryCache.Clear(); | ||
582 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache Cleared, there are now {0} items in the memory cache", m_MemoryCache.Count); | ||
583 | break; | ||
584 | |||
585 | case "clearfile": | ||
586 | foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) | ||
587 | { | ||
588 | try | ||
589 | { | ||
590 | Directory.Delete(dir, true); | ||
591 | } | ||
592 | catch (Exception e) | ||
593 | { | ||
594 | LogException(e); | ||
595 | } | ||
596 | } | ||
597 | |||
598 | foreach (string file in Directory.GetFiles(m_CacheDirectory)) | ||
599 | { | ||
600 | try | ||
601 | { | ||
602 | File.Delete(file); | ||
603 | } | ||
604 | catch (Exception e) | ||
605 | { | ||
606 | LogException(e); | ||
607 | } | ||
608 | } | ||
609 | |||
610 | break; | ||
611 | |||
612 | default: | ||
613 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] Unknown command {0}", cmd); | ||
614 | break; | ||
615 | } | ||
616 | } | ||
617 | else if (cmdparams.Length == 1) | ||
618 | { | ||
619 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache counts - Display the number of cached assets"); | ||
620 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearmem - Remove all assets cached in memory"); | ||
621 | m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk"); | ||
622 | |||
623 | } | ||
624 | |||
625 | |||
626 | } | ||
627 | |||
628 | #endregion | ||
629 | |||
528 | } | 630 | } |
529 | } | 631 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index f261c16..02befda 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -9477,8 +9477,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9477 | return; | 9477 | return; |
9478 | } | 9478 | } |
9479 | 9479 | ||
9480 | System.Text.ASCIIEncoding enc = | 9480 | System.Text.UTF8Encoding enc = |
9481 | new System.Text.ASCIIEncoding(); | 9481 | new System.Text.UTF8Encoding(); |
9482 | string data = enc.GetString(a.Data); | 9482 | string data = enc.GetString(a.Data); |
9483 | //m_log.Debug(data); | 9483 | //m_log.Debug(data); |
9484 | NotecardCache.Cache(id, data); | 9484 | NotecardCache.Cache(id, data); |
@@ -9524,29 +9524,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
9524 | 9524 | ||
9525 | if (NotecardCache.IsCached(assetID)) | 9525 | if (NotecardCache.IsCached(assetID)) |
9526 | { | 9526 | { |
9527 | AsyncCommands. | 9527 | AsyncCommands.DataserverPlugin.DataserverReply(assetID.ToString(), |
9528 | DataserverPlugin.DataserverReply(assetID.ToString(), | 9528 | NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); |
9529 | NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); | ||
9530 | ConditionalScriptSleep(100); | 9529 | ConditionalScriptSleep(100); |
9531 | return tid.ToString(); | 9530 | return tid.ToString(); |
9532 | } | 9531 | } |
9533 | 9532 | ||
9534 | WithNotecard(assetID, delegate (UUID id, AssetBase a) | 9533 | WithNotecard(assetID, delegate (UUID id, AssetBase a) |
9535 | { | 9534 | { |
9536 | if (a == null || a.Type != 7) | 9535 | if (a == null || a.Type != 7) |
9537 | { | 9536 | { |
9538 | ShoutError("Notecard '" + name + "' could not be found."); | 9537 | ShoutError("Notecard '" + name + "' could not be found."); |
9539 | return; | 9538 | return; |
9540 | } | 9539 | } |
9541 | 9540 | ||
9542 | System.Text.ASCIIEncoding enc = | 9541 | System.Text.UTF8Encoding enc = |
9543 | new System.Text.ASCIIEncoding(); | 9542 | new System.Text.UTF8Encoding(); |
9544 | string data = enc.GetString(a.Data); | 9543 | string data = enc.GetString(a.Data); |
9545 | //m_log.Debug(data); | 9544 | //m_log.Debug(data); |
9546 | NotecardCache.Cache(id, data); | 9545 | NotecardCache.Cache(id, data); |
9547 | AsyncCommands.DataserverPlugin.DataserverReply(id.ToString(), | 9546 | AsyncCommands.DataserverPlugin.DataserverReply(id.ToString(), |
9548 | NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax)); | 9547 | NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax)); |
9549 | }); | 9548 | }); |
9550 | 9549 | ||
9551 | ConditionalScriptSleep(100); | 9550 | ConditionalScriptSleep(100); |
9552 | return tid.ToString(); | 9551 | return tid.ToString(); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index bca019b..726b37a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -1457,7 +1457,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1457 | notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " | 1457 | notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " |
1458 | + textLength.ToString() + "\n" + notecardData + "}\n"; | 1458 | + textLength.ToString() + "\n" + notecardData + "}\n"; |
1459 | 1459 | ||
1460 | asset.Data = Encoding.ASCII.GetBytes(notecardData); | 1460 | asset.Data = Encoding.UTF8.GetBytes(notecardData); |
1461 | World.AssetService.Store(asset); | 1461 | World.AssetService.Store(asset); |
1462 | 1462 | ||
1463 | // Create Task Entry | 1463 | // Create Task Entry |
@@ -1522,7 +1522,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1522 | AssetBase a = World.AssetService.Get(assetID.ToString()); | 1522 | AssetBase a = World.AssetService.Get(assetID.ToString()); |
1523 | if (a != null) | 1523 | if (a != null) |
1524 | { | 1524 | { |
1525 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | 1525 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); |
1526 | string data = enc.GetString(a.Data); | 1526 | string data = enc.GetString(a.Data); |
1527 | NotecardCache.Cache(assetID, data); | 1527 | NotecardCache.Cache(assetID, data); |
1528 | } | 1528 | } |
@@ -1575,7 +1575,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1575 | AssetBase a = World.AssetService.Get(assetID.ToString()); | 1575 | AssetBase a = World.AssetService.Get(assetID.ToString()); |
1576 | if (a != null) | 1576 | if (a != null) |
1577 | { | 1577 | { |
1578 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | 1578 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); |
1579 | string data = enc.GetString(a.Data); | 1579 | string data = enc.GetString(a.Data); |
1580 | NotecardCache.Cache(assetID, data); | 1580 | NotecardCache.Cache(assetID, data); |
1581 | } | 1581 | } |
@@ -1632,7 +1632,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1632 | AssetBase a = World.AssetService.Get(assetID.ToString()); | 1632 | AssetBase a = World.AssetService.Get(assetID.ToString()); |
1633 | if (a != null) | 1633 | if (a != null) |
1634 | { | 1634 | { |
1635 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | 1635 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); |
1636 | string data = enc.GetString(a.Data); | 1636 | string data = enc.GetString(a.Data); |
1637 | NotecardCache.Cache(assetID, data); | 1637 | NotecardCache.Cache(assetID, data); |
1638 | } | 1638 | } |