When to expand a web server's unshared connection?

Someone asked on Server Fault:

We have a 3 mbps by 3 mbps dedicated, unshared pipe that hosts a web server, mail server, and VoIP/web browsing traffic for 8 employees. The web server hosts a few different sites that average about 250,000 page views total per month, with something less than a 40kb average page load size I’d estimate. I’m not sure how much of that is cached. (Side question: Is there some place in Google Analytics/Webmaster Tools that calculates actual page load size w/ taking into account cached values?)

Our #1 priority is to ensure fast load times from our web server. How should we know when we need to expand our connection beyond 3x3? Should I worry about employee web browsing traffic clogging up our download bandwidth? Will that affect page load time?

Our outbound data circuit traffic logs appear to hover around 500 kbit/second most of the time, sometimes bumps up to 1 mbps, and on occasion appears to hit our 3 mbps cap.

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

Looks like your question is a two parter.

First, the best way to ensure that your website load times are fast is to make sure you are not maxing out your bandwidth (looks like you occasionally hit your cap, so that shouldn’t be a problem). Employee web surfing (download) should not impact your website serving (upload) until you are maxing out the connection on a consistant basis. So, as long as you are not usually maxing out your connection, you should be fine.

Second, you might want to try to get more info on Google Analytics from webmasters.stackexchange.com as they probably have more users with more expertise on that tool over there. In addition to better knowledge of Google Analytics, they may be able to guide you to better caching plans to make the bandwidth you do have go further (assuming your site has a fair amount of static content that would make good cache candidates).

All of that said, more bandwidth will almost never hurt performance of your site, but it seems like for the time being it would be a waste of money for your situation. Keep an eye on your traffic logs and when you start hitting your cap more frequently, it might be time to increase your bandwidth.


Originally posted on Server Fault — 1 upvotes (accepted answer). Licensed under CC BY-SA.

WCF Data Service using custom UserNamePasswordValidator

Someone asked on Stack Overflow:

I am trying to setup a WCF Data Service to use my custom UserNamePasswordValidator it is working great for standard WCF Services; the problem I have is this: In my web.config I cannot specify the WCF Data Service endpoint because it does not implement a contract I can use. See below

  <service behaviorConfiguration="GetHttpsIncludeFaults" name="WCFDataService">
    <endpoint
        address=""
        binding="basicHttpBinding"
        bindingConfiguration="BasicHTTP"
        Contract="WHAT-GOES-HERE?"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

  <behavior name="GetHttpsIncludeFaults">
    <dataContractSerializer maxItemsInObjectGraph="204800" />
    <serviceCredentials>
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="pjt.UPValidate, pjt"/>
    </serviceCredentials>
    <serviceMetadata httpsGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="true" />
  </behavior>

For my normal WCF services, I simply sepcify the interface that the class implements; with Data Services I have no such interface.

If there is a better way to customize the ServiceBehavior I’m open to that, this is just the only way I know how to do it.

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

After a bit of poking around, I was able to get a new error by using this contract: System.Data.Services.IRequestHandler.

After getting past the error that the contract was not implemented by my service, it seems as if WCF Data Services only work with webHttpBinding — which does not support TransportWithmessageCredential security.

So, this doesn’t exactly answer my question; however, this appears to be the only way to secure a WCF Data Service via a custom username / password validator: http://blogs.msdn.com/b/astoriateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx

It involves using BASIC authentication, and writing your own HttpModule to have IIS delegate the authentication to your own custom username password validator. Obviously, this should only be used over HTTPS.


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

winforms switch between tabs while current one is busy doing processing

Someone asked on Stack Overflow:

i have winform (c#) with multi-tabs, the current focused tab is busy doing lengthy Async operation and embedded progressbasr “in that tab” showing the progress. i want to let the user be able to navigate to other tabs and perform other tasks in case he/she don’t wanna wait. so how i can do that in simple and robust way?

this is the lengthy op in short:

foreach (DataRow _dr in _allDt.Rows)
{
   //check if machine is online out of 100 machines list using async approach
        if (_connectionUtil.ConnectionIsOn(_dr["ipAddress"].ToString()))
            _onMachineAl.Add(_machineInfo);
    _progressBar.PerformStep();

 }

do i have to use thread?! or simpler way available? please provide code-segment or helpful source.

EDIT:

//async part:
 using (TcpClient tcpClient = new TcpClient())
            {
                IAsyncResult result = tcpClient.BeginConnect(ipAddress, 3306, null, null);
                WaitHandle timeoutHandler = result.AsyncWaitHandle;

thanks,

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

If you are already performing your task asynchronously, then the user should already be able to switch between tabs because the async operations will not be blocking the UI thread.

If you are not really doing your task asynchronously the user will not be able to do much of anything because you are blocking the UI thread.

That being said, I suspect you are in the second camp, so something like this should help you get going:

var mi = new MethodInvoker(() =>
{
    foreach(dataRow _dr in _allDt.Rows)
    {
        if(_connectionUtil.ConnectionIsOn(_dr["ipAddress"].ToString()))
            _onMachineAl.Add(_machineInfo);
        this._progressBar.Invoke(() => { _progressBar.PerformStep(); });
    }
});
mi.BeginInvoke(null, null);
Notable comments

Nate (0 upvotes): You need to define a callback method, and provide it in the mi.BeginInvoke() call.


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

Need advice on setup for large Silverlight site

Someone asked on Server Fault:

Possible Duplicate:
Can you help me with my capacity planning?

Hopefully someone on here will be nice enough to give some advice on what setup we should go with. I’m not a sys admin, just a developer, so I’m not entirely sure what all will need to be involved in scaling the web app we’re building out.

We’re building a SaaS web app using Silverlight, with a MS SQL database on the backend, and WCF service calls. The silverlight app itself, currently, is 6MB (not obfuscated or compressed in anyways yet), and will not get much larger. We’re potentially looking at hundreds of thousands, if not millions eventually, of customers using the site, and a large number of them joining as soon as the site goes live. Because it’s a SaaS application it’ll need 24/7/365 up time.

We currently have half a rack of dedicated hardware at a local data center, with 3 servers in place. 2 of them are currently maxed out and can’t handle anymore load, but our 3rd one has very little on it and it’s specs are: Proliant DL360 G7, 12 x 2.666 Ghz, Xeon E5650 @ 2.67Ghz, 49141.38MB of memory. We have a 2MB connection going to all 3 servers, burstable up to 100MB, but we’re looking at increasing this size. All 3 servers are running vSphere 4 Advanced so it can run multiple VMs.

The server itself will have no need for storage from the web app, but will need to be able to handle all the database calls and server up the Silverlight app. The database calls would consist of normal things like checking user login credentials, saving and loading some data (a typical write to the database will never be over 1MB for the largest information being saved), etc.

We’ve looked at both Azure and Amazon as an alternative to hosting ourselves, because what we don’t want to happen is after this goes live N number of people sign up for the service and we can’t handle all the bandwidth for downloading the app and all the database calls. However, Azure is very expensive, and Amazon isn’t that far behind it, but both seem like a good solution to the scalability concerns instead of adding X number of servers to our rack and tackling all that ourselves. Currently, we’re leaning towards Amazon as that seems like a better cloud solution than Azure, in addition to being a little bit cheaper.

Would it be better to just add another server to the mix, and increase our bandwidth? Should we look into 2 additional servers, 2 for hosting the site and load balancing them, and then the 3rd server for our MS SQL database? Or should we just go with Amazon and let them host everything? I’m really at a loss for what the best solution is, thanks guys.

I posted the following answer, which was chosen as the accepted answer:

You’ve said that your max WCF transaction will not be larger than 1MB, but what about the average one? Is it .95MB or is it 25KB? Operating on the assumption that your current infrastructure can handle your expected WCF load and you are mostly worried about the deployment of your .xap, I highly recommend that you deploy your 6MB .xap to the Amazon or Azure CDN (if you truely believe you will have millions of visitors in the early days). This will save your bandwidth and also keep you from managing any cloud VMs. You might even be able to get away with S3 storage instead of CDN depending on your performance requirements.

This way, you host your ASP.NET Web components of your application on your web server along with your WCF Services. This server should have LAN access to the database server. This gives you the advantages of in-house application management without the bandwidth requirements of hosting a large .xap file for millions of clients.

Notable comments

Nate (0 upvotes): Not a problem. Glad I could help. S3 is a great option if you don’t need that extra last mile of performance.


Originally posted on Server Fault — 0 upvotes (accepted answer). Licensed under CC BY-SA.

Alert height of window

Someone asked on Stack Overflow:

I’m trying to get the height of the window & document to display through an alert and also when a modal window pops up. I know I need to use $(window).height(); & $(document).height(); but other than that I’m not sure what to do.

Edit: The problem that I am trying to solve is that my modal window is adding extra pixels to the bottom of the document so I’m trying to find out the original document height and the height after the modal window is activated.

I posted the following answer, which was chosen as the accepted answer and received 6 upvotes:

Something like this

alert($(window).height());

will show an alert with the height of the window.

Notable comments

Nate (0 upvotes): @Rikudo — OP says: “I’m trying to get the height of the window & document to display through an alert” that is what I answered.


Originally posted on Stack Overflow — 6 upvotes (accepted answer). Licensed under CC BY-SA.

Explaing MVVM, MVC, MVP for a Database Developer

Someone asked on Stack Overflow:

I am from Database Development / QA background. I have not exhaustively worked on UI projects, Althought I coded DB part of it. I would like to know some basic examples for differences between MVC, MVP, MVVM patters.

On a very high level know after few reads I know

  • P - Presentation layer
  • M - Model
  • C - Controller - Interprets presentation layer and sends action to model on what to be presented

This is on a very high level note. I have not tried creating a basic simple example using MVVM, MVC, MVP.

Would appreciate if you can provide some more clarity on how this is different from typical 3 layered architecture

  • UI Layer - ASP / WPF
  • Business Layer - Web Services (.NET 2.0/WCF..)
  • DB Access Layer - EF, ADO.NET, Stored procedures

Thanks in Advance for your help

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

I think you’re confusing Design Patterns with Software Architecture, they are related but different.

A 3-layer architecture consists of UI, Logic, and Persitance code. Using something like MVC or MVVM simply provide a nice way to seperate these bits out.

In a 3-layer environment, you might have an MVVM App where the

  • Model comes from a WCF
  • The views are all WPF
  • the View-Models are C# classes which translate UI Actions into calls to the WCF Service

Those three things are simply the UI layer.

The WCF Service is your business logic layer, it exposes the Models that the UI will use, and it performs business logic on the data that it receives from the UI, then if appropriate, it invokes the persistance layer to save the changes into a database.


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

IEnumerable.Single is throwing an exception

Someone asked on Stack Overflow:

I have the following code which uses Entity Framework:

g_getWidgets = from getWidgets in g_libraryEntities.GET_Widgets() select getWidgets;
.
.
.
IQueryable<GET_Fragments_Result> iqueryable = g_getWidgets.AsQueryable<GET_Widgets_Result>();
var nameValueObject = from nv in iqueryable where nv.ID == int.Parse(key) select nv;
widget = nameValueObject.Single();

The widget = nameValueObject.Single(); line throws an exception saying “The result of a query cannot be enumerated more than once.

What is the proper way to perform this function? I just want to to return an item with the proper ID.

I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:

I would recommend using SingleOrDefault instead of FirstOrDefault.

Enumerable.FirstOrDefault()

Returns the first element of a sequence, or a default value if the sequence contains no elements.

Source: http://msdn.microsoft.com/en-us/library/bb340482.aspx

This means that if there are more than one match, only the first one found will be returned.

Enumerable.SingleOrDefault()

Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

Source: http://msdn.microsoft.com/en-us/library/bb342451.aspx

This means that if there is more than one match an exception is thrown. This is useful if having duplicate entries is a data violation.


Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.

Parse XML into an array of objects - with Silverlight / Windows Phone

Someone asked on Stack Overflow:

I am calling a restful service via the WebClient method to return some XML. I would then like to parse through the XML, extract specific fields out of each node, and turn that into an array.

I have the code working to retrieve the XML and populate it into a listbox. For some reason I cannot work out how to turn that into an array of objects.

Code so far:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        WebClient wc = new WebClient();
        wc.DownloadStringCompleted += HttpsCompleted;
        wc.DownloadStringAsync(new Uri(requestString));
    }

    private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);

            var data = from query in xdoc.Descendants("entry")
                       select new DummyClass
                       {
                           Name = (string)query.Element("title"),
                           Kitty = (string)query.Element("countryCode")
                       };
            listBox1.ItemsSource = data;
        }
    }

}

How can I turn each node into an object in an array?

Many thanks in advance! Will.

EDIT: The XML looks like this: http://api.geonames.org/findNearbyWikipedia?lat=52.5469285&lng=13.413550&username=demo&radius=20&maxRows=5

<geonames>
<entry>
<lang>en</lang>
<title>Berlin Schönhauser Allee station</title>
<summary>
Berlin Schönhauser Allee is a railway station in the Prenzlauer Berg district of Berlin. It is located on the Berlin U-Bahn line and also on the Ringbahn (Berlin S-Bahn). Build in 1913 by A.Grenander opened as "Bahnhof Nordring" (...)
</summary>
<feature/>
<countryCode>DE</countryCode>
<elevation>54</elevation>
<lat>52.5494</lat>
<lng>13.4139</lng>
<wikipediaUrl>
http://en.wikipedia.org/wiki/Berlin_Sch%C3%B6nhauser_Allee_station
</wikipediaUrl>
<thumbnailImg/>
<rank>93</rank>
<distance>0.2807</distance>
</entry>
</geonames>

I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:

What is wrong with

// convert IEnumerable linq query to an array
var array = data.ToArray(); // could also use .ToList() for a list
// access like this
MessageBox.Show(array[0].Kitty);

This will give you an array of DummyClass objects, from the IEnumerable<DummyClass> generated by the linq query.

Additionally, an array may not even be required. If all you need to do is iterate over the data, you can simply do a foreach on your data object.


Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.

How to run a C# winform in an XNA C# project

Someone asked on Stack Overflow:

I am trying to use the PDFsharp library in an XNA game. The example code I am trying to get to work is:

 static void Main() 
    {
      Renderer renderer = new Renderer();
      PreviewForm form = new PreviewForm();
      form.RenderEvent = new PagePreview.RenderEvent(renderer.Render);
      Application.Run(form);
    }

But I don’t know how to get this to run in XNA.

Is it possible to pass the graphics that are passed to the winform to the XNA graphics engine instead?

I posted the following answer, which was chosen as the accepted answer:

update 2

It appears that the original links to MSDN have been broken, I can’t seem to find them on MSDN anymore, if someone does, please update the post. In the mean time you may want to check out this codeproject article — http://www.codeproject.com/Articles/21330/Easy-Rendering-with-XNA-Inside-a-Windows-Form

update after a quick check, looks like the first link at (See also: XNA and WinForms) is the same one I found.

I recommend you look into mixing winforms and XNA, try this: http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1

Notable comments

Nate (0 upvotes): @user1306322 I have updated my post with another link and a request for anyone who finds the new location of the broken link to update the post.


Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.

.Net 4 in Windows Phone 7.1 SDK?

Someone asked on Stack Overflow:

Is .Net 4 supported in the new 7.1 SDK?

I am specifically wanting to use the System.Dynamic type if available.

I can’t find mention of it on MS’s sites.

I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:

It wont be .NET4, but it will be roughly Silverlight 4.

See also: http://forums.create.msdn.com/forums/p/88443/530374.aspx


Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.

signed letter b

Dad. Geek. Gamer. Software developer. Cloud user. Old Car enthusiast.  Blogger.


Top Posts


profile for Nate on Stack Exchange, a network of free, community-driven Q&A sites
a proud member of the blue team of 512KB club
Thoughts, opinions, and ideas shared here are my own. © 2026 Nate Bross.