I'm attempting to redevelop the software that drives http://mammothworkwear.com/ using Nancy but I'm having issues attempting to get the TTFB down to under 300ms.
My prototype is hosted in IIS, built in release mode and I have removed the web.config debug flag. If you test at any of the pages on Mammoth Workwear you will see that I have the TTFB below 50ms using a hybrid .Net framework I've built and optimised over the years. How would I achieve the same with Nancy?
This is the test code I am using.
Get["/ttfb-test"] = _ => {
return "<h1>Any faster?</h1>";
};
I figured it out. I had the FormsAuthenticationConfiguration in my Boot Strapper attached to the RequestStartup pipeline, which means it preformed the following on each request:
var cryptographyConfiguration = new CryptographyConfiguration(
new RijndaelEncryptionProvider(new PassphraseKeyGenerator("SuperSecretPass", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })),
new DefaultHmacProvider(new PassphraseKeyGenerator("UberSuperSecure", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })));
var formsAuthConfiguration = new FormsAuthenticationConfiguration
{
CryptographyConfiguration = cryptographyConfiguration,
RedirectUrl = "~/account/login",
UserMapper = container.Resolve<IUserMapper>(),
RedirectQuerystringKey = "url"
};
I moved it to the ApplicationStartup method so it only happens when the app first starts up, and it dropped the TTFB down to 2.2ms. Much better than I could have expected!
Loving Nancy!
Related
My Android app uses MediaProjection to take screenshots and record a video at the same time.
The ImageReader is used for taking screenshots when necessary, the MediaRecorder records the screen into a mp4 file.
The screenshot part is done by using
private val imageReader = ImageReader.newInstance(imageSize.width, imageSize.height, PixelFormat.RGBA_8888, 2)
private val virtualDisplay = mediaProjection.createVirtualDisplay(
"ScreenCapture",
imageSize.width, imageSize.height, screenDensity,
0, imageReader.surface, null, null
)
The video recording part is using
private val mediaRecorder = MediaRecorder().apply {
setVideoSource(MediaRecorder.VideoSource.SURFACE)
val profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)
setOutputFormat(profile.fileFormat)
setVideoEncoder(profile.videoCodec)
setVideoEncodingBitRate(profile.videoBitRate)
setVideoFrameRate(profile.videoFrameRate)
setVideoSize(imageSize.width, imageSize.height)
setOutputFile(storageProvider.recordingFileDescriptor.fileDescriptor)
prepare()
}
private val virtualDisplay: VirtualDisplay = mediaProjection.createVirtualDisplay(
"ScreenRecord",
imageSize.width, imageSize.height, screenDensity,
0, mediaRecorder.surface, null, null
)
So the same MediaProjection is used to fill an ImageReader surface and a MediaRecorder surface at the same time.
Users with Android 13 now report that only one of the surfaces will be filled. If the video recording is started after the screenshot service, the screenshot service will not receive any new images through imageReader.acquireLatestImage().
For Android 7 to 12 users, this still worked fine. They only saw this behavior when another app started MediaProjection.
Is there any way to use the same VirtualDisplay for both the ImageReader and the MediaRecorder? I can't think of any other solution.
The only existing solutions I can find are for the Camera2 API.
Is there a way in DNN 5, 6 or 7, via the DNN API to programmatically display our custom module version number (the one we set in the module manifest) so that we don't have to manually change it on each new version.
This would be handy so we can be 100% confident of the version our customers use.
Here is a function to help you with that.
public string GetModuleVersion(string moduleName)
{
DesktopModuleController objModules = new DesktopModuleController();
DesktopModuleInfo info = objModules.GetDesktopModuleByModuleName(moduleName);
return info.Version;
}
Example
string ver = GetModuleVersion( "DigArticle" );
We have a WPF application which is requesting RSS feeds through url from our MVC website using XDocument.Load() function. Although in the MVC web application we are caching the RSS page for 15 minutes, the wpf application is still requesting a new rss page every time ignoring the cache in the server. How do we use the cached pages in our WPF application?
Here is the code:
Path.Combine((Directory.GetParent(App.DisplayFilePath)).Name, "RSS.xml");
XDocument doc;
doc = XDocument.Load(this.FeedUri.AbsoluteUri);
doc.Save(cacheXmlFile);
doc = XDocument.Load(cacheXmlFile);
var feedItems = from feed in doc.Descendants("item");
Here is the code in the Server side mvc application:
[OutputCache(Duration = 900, VaryByParam = "*")]
public RssActionResult GetBranches(int gid = -1, string gname = "", int t = -1,
int tgap = 0)
{
var feedItems = new List<feedItem>();
var branches = db.usp_GetBranch(gid, gname, t, tgap).ToList();
feed.Items = feedItems;
return new RssActionResult() { Feed = feed };
}
The WPF application is requesting this action through url in the server side. Is the OutputCache attribute OK?
I'm trying to launch test for WP7 with such code:
var client = new RestClient("http://google.com");
var request = new RestRequest(Method.GET);
client.ExecuteAsync(request, response => Debug.WriteLine(response.StatusCode);
This code write HttpStatusCode=0 and raise error:
The type initializer for 'System.Net.WebRequest' threw an exception.
System.TypeInitializationException
How to fix it?
UPDATE #1
For example, this code works fine in Windows Class Library, but doesn't work in Silverlight and WP7 Projects:
var client = new RestClient("http://carma.org/api/1.1/searchPlants");
var request = new RestRequest();
request.AddParameter("location", 4338);
request.AddParameter("limit", 10);
request.AddParameter("color", "red");
request.AddParameter("format", "xml");
var plants = client.ExecuteAsync(
request, response => Assert.AreEqual(HttpStatusCode.OK, response.StatusCode));
I know that nunit can throw strange exception on windows phone 7, make sure you got the silverlight version, that may fix your problem.
More details are availables here => NUnit with Windows Phone 7
How can I efficiently and effectively detect the version and, for that matter, any available information about the instance of Silverlight currently running on the browser?
The Silverlight control only has an IsVersionSupported function, which returns true / false when you give it a version number, e.g.:
if(slPlugin.isVersionSupported("2.0")) {
alert("I haz some flavour of Silverlight 2");
You can be as specific as you want when checking the build, since the version string can include all of the following:
major - the major number
minor - the minor number
build - the build number
revision - the revision number
So we can check for a specific build number as follows:
if(slPlugin.isVersionSupported("2.0.30523")) {
alert("I haz Silverlight 2.0.30523, but could be any revision.");
Silverlight 1.0 Beta included a control.settings.version property, which was replaced with the isVersionSupported() method. The idea is that you shouldn't be programming against specific versions of Silverlight. Rather, you should be checking if the client has at least verion 1.0, or 2.0, etc.
That being said, you can get the Silverlight version number in Firefox by checking the Silverlight plugin description:
alert(navigator.plugins["Silverlight Plug-In"].description);
Shows '2.0.30523.8' on my computer.
Note that it is possible to brute force it by iterating through all released version numbers. Presumably that's what BrowserHawk does - they'll report which version of Silverlight the client has installed.
I got this from http://forums.asp.net/p/1135746/1997617.aspx#1997617 which is the same link Stu gave you. I just included the code snippet.
Silverlight.isInstalled = function(d)
{
var c = false, a = null;
try
{
var b = null;
if(Silverlight.ua.Browser == "MSIE")
b = new ActiveXObject("AgControl.AgControl");
else
if(navigator.plugins["Silverlight Plug-In"])
{
a = document.createElement("div");
document.body.appendChild(a);
a.innerHTML = '<embed type="application/x-silverlight" />';
b = a.childNodes[0]
}
if(b.IsVersionSupported(d))
c = true;
b = null;
Silverlight.available = true
}
catch(e)
{
c=false
}
if(a)
document.body.removeChild(a);
return c
};
found this site that detects the full version of silverlight- silverlight version (aka silverlightversion.com)
As mentioned in the above comments there is currently no efficient direct way to get the installed Silverlight version number (that works cross browser platform).
I wrote a post on how to workaround this problem and detect the Silverlight major version number (including version 3) programmatically and more efficiently using JavaScript.
You can find the code and the post at:
http://www.apijunkie.com/APIJunkie/blog/post/2009/04/How-to-programmatically-detect-Silverlight-version.aspx
Good luck!
Environment.Version will do what you want! Supported since Silverlight 2.0
Look in silverlight.js:
http://forums.asp.net/p/1135746/1997617.aspx#1997617