Monday, February 6, 2012 by Nate Bross
Someone asked on Server Fault:
I hope this is the correct section, this is my first time here, I have a question please.
I think that a lot of people are asking this question in this period.
We are managing a server of a game with a big exchange of data (minecraft) and we have to buy a new server, but we have to find where is the best way to mantain the map.
We have three option in Ubuntu enviroment, Ramdisk, SSD and SAS, do you know who will be the faster to mantain the map (1.9gb, but a lot of small files, huge transfer)?
I am not really an expert of this, so if I can I would like to add the link of the server that we would like to rent, so maybe you can be more precise, if I can put the link please tell me, I will delete it. http://www.hetzner.de/en/hosting/produkte_rootserver/ex4s
Thanks for your time and sorry about my bad english. Best Regards,
Paolo
P.s I don’t know nothing more, so please explain everything :(.
I posted the following answer, which was chosen as the accepted answer and received 6 upvotes:
You will need to take into account the pro/con for each of the things you’ve listed.
Ramdisk
Fastest option you listed, but it will still require a real HD to save data to. If the server goes off-line, anything on the RAMDISK will be lost unless it is persisted to long-term storage. Also requires a lot of memory on your server.
SSD
Very fast, and good for tons of small IO. Very expensive and not much capacity.
SAS (I assume you mean 10k/15k drives, not 7.2k NL-SAS)
Still pretty fast, comes in much larger sizes.
What I would do
If it were me, I would start some monitoring, to see if disk IO is really a limiting factor, for a game server, my guess is that its CPU or network that is your limiting factor. If you find that disk IO is responsible, I would personally grab a pair of 15k SAS drives and run them in RAID-1 (or if money is no object, I’d get 4 or 8 and run them in RAID-10).
Originally posted on Server Fault — 6 upvotes (accepted answer). Licensed under CC BY-SA.
Thursday, February 2, 2012 by Nate Bross
Someone asked on Stack Overflow:
I have an app where the user can send some data via email, sort of like a report. This works fine but I would like some more formatting. The best thing would be if it was possible to create some HTML code and add it to the mail. Is this possible?
I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:
With Windows Phone 7 you can only start the EmailComposeTask which does not have any way to include HTML based email. You will need to send this from a web service, which in all honesty is probably the better option anyway, as you’ll be able to log who sent what when, etc.
Notable comments
Nate (0 upvotes): Again, to include an attachment, a web service is the way to go.
Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.
Monday, December 19, 2011 by Nate Bross
I asked this on Database Administrators:
I have Log and LogItem tables; I’m writing a query to grab some data from both. There are thousands of Logs and each Log can have up to 125 LogItems
The query in question is complicated so I’m skipping it (if someone thinks it’s important I can probably post it), but when I ran SSMS Estimated Query plan, it told me a new Non-Clustered index would improve performance up to 100%.
Existing Index: Non-clustered
Key Colums (LogItem): ParentLogID, DateModified, Name, DatabaseModified
Query Plan Recommendation
CREATE NONCLUSTERED INDEX [LogReportIndex]
ON [dbo].[LogItem] ([ParentLogID],[DatabaseModified])
Just for fun, I created this new index and ran the query and much to my surprise, it now takes ~1 second for my query to run, when before it was 10+ seconds.
I assumed that my existing index would cover this new query, so my question is why did creating a new index on the only columns used in my new query improve performance? Should I have an index for each unique combination of columns used in my where clauses?
note: I don’t think this is because the SQL Server is caching my results, I ran the query about 25-30 times before I created the index and it consistantly took 10-15 seconds, after the index it is now consistantly ~1 or less.
GSerg answered (21 upvotes):
Order of columns in an index is important. If filtering requires column 1 and 4 from index, the index is not going to help. It’s only useful when filtering by the first N consecutive columns.
This is because index is a tree. You can’t efficiently select all nodes of the tree where column3 = something, because they are scattered all other the place, belonging to different values of column1 and column2. But if you know column1 and column2 as well, locating the right branch in the tree is a no brainer.
Originally posted on Database Administrators — 20 upvotes. Licensed under CC BY-SA.
Wednesday, December 7, 2011 by Nate Bross
Someone asked on Stack Overflow:
I am trying to figure out what the best way would be for me to find out what portions of my application are taking the longest time to run (Largest run cost). The application is not overly complex, but I wanted to make ensure that I have all of the pieces properly tuned so that I could potentially handle a greater load.
Application: Loads / shreds xml documents and dumps the contents into a DB. The application is using Linq to XML to parse the xml, and SQL Server TVPs to pass the data down to the DB. Because I am using TVPs I have one round trip to the DB even when there are collections of data the data is not big (XML files at most 1MB).
Any suggestions on how to isolate the bottlenecks would be greatly appreciated.
As always greatly appreciate the feedback.
I posted the following answer, which was chosen as the accepted answer and received 5 upvotes:
You may want to check out the StopWatch class. You can sprinkle it into your code like this:
// load XML Method
var stopWatch = new Stopwatch();
stopWatch.Start();
// run XML parsing code
stopWatch.Stop();
var xmlTime = stopWatch.Elapsed;
// SQL Server dump Method
var stopWatch = new Stopwatch();
stopWatch.Start();
// dump to SQL Server
stopWatch.Stop();
var sqlTime = stopWatch.Elapsed;
This is a low-tech way to take general measurments. For a simple application this is probably more efficient than a profiler, since your application only has two real points for a bottle neck. That said, learning how to use a profiler may be worth your while.
Originally posted on Stack Overflow — 5 upvotes (accepted answer). Licensed under CC BY-SA.
Friday, December 2, 2011 by Nate Bross
Someone asked on Stack Overflow:
I should make an application for Windows Phone 7.5, which is able to communicate bidirectionally with the same application installed on other devices with the same operating system.
I read that the Silverlight version on Windows Phone only supports BasicHttpBinding, so I think I will have to implement bi-directional mode using the BasicHttpBinding: for example, the node that accepts the incoming “connection” could send a GUID to the requesting node in order to identify a kind of session (this GUID should then be sent for each subsequent communication between two nodes).
Are there better alternatives?
The core of all communication is communication between two nodes:
- there are three types of requests (one of these must be very frequently, say every 10 seconds);
- the node which receives a request, could answer or ignore the request.
What is the impact on performance?
I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:
I don’t think there is a way to accept connections on WP7 devices, see here.
Since WP7 doesn’t support poll duplex WCF services either, I recommend you manually implement it, similar to this: http://www.dominikschmidt.net/2010/12/windows-phone-7-callbacks-and-duplex-wcf/
You will need a central server which all clients continually post messages to. Every time a Client1 calls the server, it checks the database to see if Client2 sent Client1 a message. If so, that message is included in the response to Client1.
Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.
Saturday, November 26, 2011 by Nate Bross
Someone asked on Game Development:
I’ve got a game that has 3 basic sprites, at the moment I’m loading 8 images into each sprite for animating. Each character class has a sprite object. if I’ve got 10 characters on screen at once then that’s 80 images loaded in to memory. Can I make a central sprite class that only holds 8 images for each of the 3 sprites, then get the character objects to request the relevant images from the central sprite class, thereby massively reducing the memory required for the images?
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
You can and you probably should. I believe that in Java (as in C#) objects are going to be passed by reference, so you should get this behavior by default without doing any extra work.
Code like this:
Sprite spr = Sprite.LoadFromFile("c:\sprite.s");
Character c1 = new Character(spr, x1, y1);
Character c2 = new Character(spr, x2, y2);
Character c3 = new Character(spr, x3, y3);
Should give you three Character objects all referencing the same Sprite object.
A quick search shows that I stand corrected. Java is in fact pass-by-value; however, since java has “pointers” the result in the code above should remain the same. Java passes the pointer to the sprite by value; but they will all still “reference” the same sprite.
Notable comments
Nate (0 upvotes): That is my understanding, yes.
Originally posted on Game Development — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Monday, November 21, 2011 by Nate Bross
Someone asked on Stack Overflow:
I’m having trouble with using UpdatePanel and changing the ‘class’ attribute of a control inside a repeater by javascript.
Here some code:
—on the aspx—
<script type="text/javascript">
function changeClass(ctl) {
if (ctl.className == "marked") {
ctl.className = "unmarked";
} else {
ctl.className = "marked";
}
}
</script>
<!-- some html -->
<asp:UpdatePanel ID="upp" runat="server">
<ContentTemplate>
<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound">
<ItemTemplate>
<a id="aButton" runat="server" href="javascript:void(0)">
<!-- some other controls -->
</a>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
—Codebehind—
protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
MyClass obj = (MyClass)e.Item.DataItem;
((HtmlAnchor)e.Item.FindControl("aButton")).Attributes.Add("class", "marked");
//some other code....
}
}
//method called after the bind on 'rpt1'
private void mymethod()
{
foreach (RepeaterItem ri in rpt1.Items)
{
HtmlAnchor aButton = (HtmlAnchor)ri.FindControl("aButton");
if (Must-be-unmarked)
aButton.Attributes.Add("class", "unmarked");
aButton.Attributes.Add("OnClick", "changeClass(this);");
}
}
The problem is, when I click on an “aButton” the class is changed normally, but when I come in codebehind and get de ‘class’ of control to check if it’s marked or unmarked, I only get the controls marked in ItemDataBound of repeater, not the “aButton”s marked by me at execution time.
here is what I do to get the “aButton”s marked:
private void checkMarked()
{
foreach (RepeaterItem ri in rpt1.Items)
{
if (((HtmlAnchor)ri.FindControl("aButton")).Attributes["class"] == "marked")
{
//do something...
}
}
}
I posted the following answer, which was chosen as the accepted answer and received 1 upvote:
When you change class property from client-side code, the server side will not know about it.
You’ll need to add a hidden <input> with marked/unmakred so you can check the contents from the server on a post-back.
Another approach would be to sipmly have your javscript postback to the server directly when an item changes from marked/unmakred.
Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.
Friday, November 18, 2011 by Nate Bross
Someone asked on Stack Overflow:
Hello everyone I have a question that I will describe as good as I can. I have project that resides in the folder on my server the path for url is like
www.domain.com\\project now what I am trying to achieve is to have a \project directory be only accessible if user is login. scenario would be the user opens the url www.domain.com and he see the login screen if he logins path \project will be accessible if he does not and try’s to go to any file in the direcoty or directory it should give him an error and redirect him back to login screen. I am using MVC3 in my project but I can write the login screen in asp.net web forms. I am also want to authorization be based in db a table with user logins so when the user logins it validates based on the information in the table. I am not looking for roles or privileges just a straight access to url based on login. If someone can show an example or a code sample on how to achieve this I will be greatly appreciated it.
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
In your web.config try this:
<system.web>
... other stuff
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
... other stuff
</system.web>
... more stuff
// secure only one directory [goes at the same level as your standard <system.web>]
<location Path="Project">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Monday, November 14, 2011 by Nate Bross
Someone asked on Game Development:
Is it possible to make an MMO game in Flash CS5 with ActionScript 3.0?
I’m not asking how, but I’d also like to see some examples if it’s already been done.
I posted the following answer, which was chosen as the accepted answer and received 5 upvotes:
It depends what you mean by “MMO” it would be quite possible to build an MMO client in Flash.
The real question becomes what does your server side software look like? How real-time is this game going to be? Are you talking an MMO like World of Warcraft or something similar to a text-based-turn-based game like Kings of Chaos?
IMHO, you could make a very fun turn-based game in Flash. With the proper server software, you could probably make a real-time game as well, the problem you’ll have is loading a big seamless world that many MMOs feature now.
I think you may be trying to shoehorn your existing skills onto game development (I say go for it). I’d recommend starting out with some fun, casual Flash based games. Once you have that under your belt, move on to something bigger.
Originally posted on Game Development — 5 upvotes (accepted answer). Licensed under CC BY-SA.
Wednesday, November 9, 2011 by Nate Bross
Someone asked on Stack Overflow:
I had to add a new column to my table so I did that in the database and then I removed the table from the dbml file and readded the one with the new column. So the column I added was (_isActive bit null allowed) and this messed up my designer file. It has added a duplicate definition of some of the attributes like: private bool isActive and other one as private System.Nullable @_isActive; Also added additional stuff. I had to delete the designer file and reload it with old one. How should I go to make this change in the dbml file?
I posted the following answer, which was chosen as the accepted answer and received 1 upvote:
With Linq-To-SQL I believe you need to use the designer to remove and add a table after you have made a schema change.
If you edited the code-behind file, those changes can cause problems. There is a reason all the classes there are defiend as partial class
So, I suspect your best option is to delete your DBML and start again.
Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.