Etherpunks' blog is for me to talk about misc things. This can include person projects (such as a page in the wiki or writing an app) to things that happen in my daily life. Comments are allowed, but will need approval due to spamming. It is important to note that I like profanity. A lot. I'm also not bashful and while I try to keep this blog SFW I sometimes mess up and put things that are a little.. TMI... my friends frequently look at me funny because of this. You have been warned.
This page is going to list all the books I own, by category. Eventually I will write a 'media' module which will take care of all this, tagging, and different media formats (such as DVD, treeware, etc).
Here is a temporary link until I get all the books in one spot.
This is a program I wrote to help clean up directories such as .svn, bin, obj, etc. This came from needing to zip stuff up so I could email them only to find out several hundred megs of data was consumed by crap.
This version is cleaned up *dramatically* and uses threading (BackgroundWorkers) so the app doesn't appear locked up. It even features a cancel button when going through the directories have there is no cancel when it comes to deleting (however the OS will prompt you to make sure it's what you /really/ want).
Attached is the source built from Visual Studio 2008 SP1 and the binaries.
A few months ago I purchased a Linksys WRT-54GL hoping to decrease my power usage without losing too much functionality. I very quickly went to DD-WRT and found it to rock. I'm very happy with it and likely won't upgrade unless of a severe critical bug.
I did, however, find one setting incredibly useful when dealing with torrents: Adjust your TCP timeouts. I adjusted my TCPto be 120 (TCP is defaulted to 3600 while UDP is 120 already). This way, when you turn off your torrent app, in 2 minutes all those connections die off.
The main benefit for this is if you game and you want to game NOW, you don't have to wait too long before your lag issues go away. Another main advantage is that it helps prevent connection overload -- which is why most routers lock up after a few weeks and you have to reboot them, if you torrent.
Given the quantity of torrenting I do, uploaded ~ 1TB of data, I really liked this.
Maybe one day I'll drop some testicals and do some hardware hacking on the thing.
edit: links to home.etherpunk.com will likely not work properly since I'm moving servers around. I'll fix this when I get a chance.
Yesterday a bug hit me. I wanted to see what was the fastest way to read and write data to a database. The methods of which to do the writing was the fun part. I chose LINQ, SqlCommand (2.1 Pakala), and SubSonic. There are a couple different ways to use each and I wondered which way was the right way. I found some interesting results.
Firstly, I'd like to provide the link to the code that I used so you can verify the results yourself or critique my methods. It can be found at: http://home.etherpunk.com/svn/DatabaseSpeedTest/DatabaseSpeedTest/WriteT...
Secondly, the database structure is *very* simple. The only table I'm using is a TypeLookup table which is essentially a primary key (set as a unique identifier), a name, and createdon fields. This is a table I'm using for another application (that application is exceptionally simple, which is why I chose it).
Here are the results (in seconds):
Running write tests. Creating 10000 entities.
LINQ using Attach: 3.523
LINQ using InsertOnSubmit: 38.25
SqlCommand Dynamic Sql (constant connection string): 15.989
SqlCommand Dynamic Sql (static connection string): 15.123
SqlCommand Individual (constant connection string): 8.86
SqlCommand Individual (static connection string): 9.526
SqlCommand Individual More Effecient (constant connection string): 8.862
SqlCommand Individual More Effecient (static connection string): 9.527
SqlCommand with StringBuilder (constant connection string): 6.056
SqlCommand with StringBuilder (static conenction string): 6.144
SubSonic with individual saves: 8.945
SubSonic using Collections: 9.654
An intersting thing is how horrible InsertOnSubmit() is for LINQ... I'm guessing that I'm using it wrong because holy crap... it doesn't scale well at all however using the Attach() method seems to be significantly faster than everything else. I tried using 100,000 entities however many of these just didn't scale well and it took longer than 10 minutes. I'll probably do that later tonight and update this blog with those numbers in the morning.
I should also note that I learned how to use LINQ yesterday... so it's very likely I'm not using it properly but it's a pain to find good and simple examples. Luckily Visual Studio 2008 came with some which got me going... but some of those were either lacking in areas I needed or more complex than I cared for -- fortunately Google to the rescue.
I find it very intersting that opening and closing a connection have next to zero overhead for creating entities. Granted, this is likely using pooling but still -- I would have thought even the code overhead would have been more than that. I also find it intersting how much faster a constant value is than a static value -- the read access must really be something to take in to consideration.
Something I learned about LINQ is it seems to bring over the constraints from the database in to the code itself while SubSonic seems to be just setting up classes and being fairly stupid (which isn't neccassarily a bad thing and can give you more control in certain situations). Because of this, I wasn't able to take advantage of the LINQ collections because it forced me to make a unique ID upon adding it or else it would throw an exception ("Cannot add an entity with a key that is already in use.") -- one which I haven't figured out how to get around just yet because I don't want to assign those keys in code, I want those to be assigned when they are saved and have the database assign them.
I'd really like to compare how LINQ handles revision control systems against SubSonic... since regenerating that SubSonic DAL sucks because you normally delete the folder, recreate the folder, regenerate the DAL -- and doing all that in a version control system can be very slow. LINQ doesn't seem to need tons of files however for bigger databases it seems to take longer generating the XML. This was using LINQ .NET 3.5 SP1.
SubSonic also doesn't seem to handle constraints very well or at least when I placed constraints forcing a db structure such as linking PersonID's or forcing UNIQUE names (e.g. room names) it seemed to not finish the code upon generation but never threw an error and as such it would never compile to generated DAL. As such, I had to choose a simple table structure to make sure the playing field was level however given a database that needs to maintain ACID compliance and one of moderate size (will have more than a couple users and more than a couple tables), I would not choose SubSonic (which 2 weeks ago I would not have said this) however I plan on looking back at it later. This was using SubSonic 2.1 Pakala which was somewhat recently released -- so I'm hoping it's just a few bugs to work out. However if I were using Sqlite -- I would likely choose SubSonic.
I've recently come to the conclusion that using constraints is the only sane way of keeping a database consistant since everything else requires a *ton* of overhead checking (and you will still never be 100% safe without doing row-level or table-level locking) or you take a chance at your database being inconsistant or having it slowly become more corrupt over time. I'm still trying to figure out how to cleanly handle exceptions thrown which violate these constraints... without having try/catches over ever database write. Herely lately I've been pushing for everything being saved in a stored procedure and wrapped in a transaction. This was accomplished only because I found out how to use the XML datatype in SQL Server and use it to pass in mini-datatables. Doing this seems to have made things *really* fast and most likely faster than LINQ, SqlCommand, or SubSonic will ever be because it's all in the database... only catch is you have a metric ton of variables for the save stored procedure -- which is where a strongly type data access layer comes in handy.
The next areas I plan on working on is the read tests and then a full database population read/write test -- with using constraints and without constraints. I'm very curious to know what I'll find.
This module allows players to report abuse of other players.
To bring up the menu, a player will type /report
The menu that gets brought up will look like:
After selecting an action, it a row in to a database will be added for admins to see. Cron will be needed to parse this and should be called at a fairly quick interval (every minute).
A default mailer script will be provided as well as a basic page to show results.
Table format for table 'reportabuse':
The 'Threaded Listen Server' (TLS) is meant to be a DLL which can nicely integrate in to any .NET application. It's meant to sit as a server, waiting for a request. Given a specific request (such as 'status') it will return a response (by starting an event) allowing a client to easily manage many machines. For example, if you have many clients which run an application of yours you can insert this module and it can easily poll those applications and get a return status.
Outlining Exact Objectives
Like I said before, I really dislike try/catches. They slow your code down and they are generally used when you don't know how to appropriatly handle data. For example, using try/catch to convert a string to an int versus using Int32.TryParse(). Yes, I've really seen this on the wild... and not from an amatuer either. I'll openly admit, I'm an OK programmer. I have much to learn. I just learned how to implement Transactions in code. I have learned how to make .NET crash so hard -- it throws an exception *outside* of your applications domain. This means you can't catch it. At all. But I'll get to that in a minute. I'd like to start by explaining when it's a good idea to use a try/catch.
Using try/catches are a good when you can't calculate everything. For example, network issues. Sure -- you can ping a server. Doesn't mean the database is up. Sure, you can do many other things such as test the database (SELECT 0 comes to mind) however you can't calculate the network being dropping in the middle of everything. So far the only method I've found that is reliable is using a try/catch because the medium is so volatile, even after doing your check it can go down. So, the answer is to use a transaction (if you are doing multiple inserts) and using a try/catch looking for a SqlException. But this won't stop everything... I'll explain how I pissed off .NET with pictures and network failures.
Apaprently .NET handles System.Image in an intersting way. It is only a pointer/reference to the location of the file. What this means is that if you reference an image across the network and it goes down -- System.Image throws an exception. In fact it throws a pretty gnarly exception that you can't catch. Here is how you can reproduce this. Create a blank project. Drop in a timer and set the interval to 15 second or an amount that a little longer than it will take you to unplug your network cable. Modify the form load to engage the timer and have the form load the image. Have the form hide itself. On the timer tick, have the form display itself (this will cause the image to be repointed and thus having to look at the network to pull the image). Start the app and then unplug your network cable. It should have a nasty crash. One you can't stop. Another thing I learned is that it puts a lock on the file so you can't delete/modify it. So far the only idea I've come up with to have an in-memory cache is to load it in to a byte array from a stream and have you rference that byte array. What I don't know is if it's still a pointer to the file. I might assume that that stream will push the bits in to the byte array and thusly remove the dependance of the network.
Using SubSonic the code to implement transactions and SqlException is pretty straight foreward and you would just surround your .Saves (personally, I like to place everything in the try/catch block just to make the code look cleaner) with a System.Transactions.TransactionScope. A TransactionScope will put a lock on your table when doing an insert, and for good reason. This is because you can't rely on the data to be inserted until you do a commit. So this will stop people from seeing the data (or any in the table for that matter) so they don't reference it and then have the transaction cancelled and then you have an inconsistant database. If you want a way around that then you should use System.Transactions.TransactionOptions. TO has only two properties -- timeout and the scope options. Microsoft has an article explaining the enumerations and their values and which ones you would want to use for which circumstances. I should probably link it but I'm too lazy.
Unwiped, unshowered, recently used ass -- this is what D-Link reminds me of and is what I tell people (even at the store) about D-Link and their technical support. It sucks. Their hardware sucks. Everything about them sucks. But they are cheap. So in some circumstances, people just need cheap and to work "just enough". If it breaks, don't call support.. buy a new one or use one from a company that doesn't suck. Their tech support LOVES to point fingers at anything BUT a problem of theirs. So fuck them. Err, wait... I'd probably procure some diseases if I did that... nevermind. I'll avoid it when I can. I've had this anst towards them since over a year... it still hasn't changed.
At the moment I'm swapping over to more energy effecient hardware (my laptop, as opposed to a power hungry monster server) being as most of the cpu cycles are wasted anyways.
I dropped OpenBSD temporarily to go to a D-Link router because I wanted a quick 'n dirty interface for hacking on firewall rules -- something simple and stupid. I knew D-Link sucked... badly, but it was all I had... I now recall how bad.
It's firewall doesn't purge rules correctly AND is limited in how many rules it can have. So guess what this means? This means about 1/4 of my rules are broken and suck up 1/4 of the rules I need. FUCK. I'm sure if I call tech-support they will ask me to reflash my router... because their tech support sucks like that. I don't think I've EVER had a good experience with them and which is why my other hardware went to Netgear (I haven't experienced their tech support yet, so yeah...). So... at this point I'm torn between fighting OpenBSD's PF -- which I think I have it setup 90% the way I want... I'm just tired of messing with it right now and want to start on another project -- OR -- I can just deal with not having port 80 working... which at this exact point in time is OK with me... I wonder if FTP will work. It has 4 rules allowing the same port, protocol, and IP... and a fifth one pointing to the old IP with same info. I suppose the question now is, is it first matching or last matching?
I went to try Debian instead of Ubuntu because a friend of mine recommended it against Ubuntu if I wanted sanity from updates. I found this link to get websvn going. I also ended up having to use this link to get SSL support going, but I may have goofed up something on that first link somewhere (likely). I did try for WebSVN but didn't seem to get far with that but it's not important. The way I have it now it should be anon read and auth write.
Next steps are to get HLDS running so I can write a few modules. Then I'll probably start working on MDS for a little bit, and then I'll get the OpenBSD firewall going... unless D-Link pisses me off... at which point I will ritualisticly burn the bastard.
For what it's worth I've decided to re-focus on certain things.
Two of the computer aspects are: OpenBSD and programming (C#, .NET 2.0 compatible code, but some is 3.5).
I want to update the OpenBSD-Wiki and start making major progress on the MetaDataSystem. I've made good progress with it so far using SubSonic and SQLite. A few gotchya here and there though.
The third thing is going to the gym more religously. I'm pretty reliably at going at least twice a week doing 3 body parts each day. The pattern is usually Back/Bi/Legs and Chest/Tri/Shoulders with at least a day rest in between.
I think I'm going to switch that to Monday and Wednesday are workouts with minor aerobic while Tuesday and Thursday are major aerobic and swimming and relaxing in the spa. Sundays I'm trying to get out and swim at the local pool. Alochol is usually involved there. Saturday nights usually involve alcohol too... and be being an idiot, but that's half the fun isn't it? going "I just did NOT do what I think I did? FUCK!". Usually laughing about it the next day.