Hi guys,
can a hashtable be faster than a sql server??
i made my own O/R mapping with an "entity cache" (caching all mapped
objects). So, when i get some data from my sql server, i map that data to an
entity-object and i leave a copy of it in the entity cache.
the entity cache is a simple hashtable, which stores as key:
the ID of the entity ( the same id as the primary key of the sql-table ) and
the entity type.. and as value: the object itself.
so, when i access the cache, i say: Contact contact = EntityCache.Get( 5109,
typeof( Contact ) )
i just made some tests and i filled the cache with 1 mio. contacts.
the result: searching the hashtable for one value, costs mostly ~0.000.007
sec! (nanoseconds).. thats amazing!! my sql server can never reach such
values! my dev. machine is just an amd 2 ghz with 1 gb ram.
of course i can search in the cache only by id, but it is the same way as
the sql server would search for an index, isn'it? i thought about, to setup
an extra caching-server... just read a big sql-table and store everything in
the entity-cache..(updating/inserting/deleting or searching by other values
is another topic).
i cant believe it!
steven. 6 6525
Hi Steven,
There's nothing surprising. The Hashtable is (well, let's assume so) in the
RAM, and its searching algorithm is optimized for performance. The SQL
Server keeps indexes on disk, so even if the algorithm is similar, loading
the indexes from disk takes time (as well as transmitting the result set
over the network or over a named pipe).
--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Steven Wolf" <ap****@gmx.net> wrote in message
news:51**********************************@microsof t.com... Hi guys,
can a hashtable be faster than a sql server?? i made my own O/R mapping with an "entity cache" (caching all mapped objects). So, when i get some data from my sql server, i map that data to an entity-object and i leave a copy of it in the entity cache.
the entity cache is a simple hashtable, which stores as key: the ID of the entity ( the same id as the primary key of the sql-table ) and the entity type.. and as value: the object itself.
so, when i access the cache, i say: Contact contact = EntityCache.Get( 5109, typeof( Contact ) )
i just made some tests and i filled the cache with 1 mio. contacts. the result: searching the hashtable for one value, costs mostly ~0.000.007 sec! (nanoseconds).. thats amazing!! my sql server can never reach such values! my dev. machine is just an amd 2 ghz with 1 gb ram.
of course i can search in the cache only by id, but it is the same way as the sql server would search for an index, isn'it? i thought about, to setup an extra caching-server... just read a big sql-table and store everything in the entity-cache..(updating/inserting/deleting or searching by other values is another topic).
i cant believe it!
steven.
Hi Dmytro,
without taking care about the network-time, namepiping etc., ms-sql/indexes
never get such results as the hashtable do.. i saw better results on
PostgreSQL...
are you sure the indexes are stored on the harddisk? i thought they were in
the RAM..
i am curious if sql server 2005 will conquer the speed as the hashtable do...
steven
"Dmytro Lapshyn [MVP]" wrote: Hi Steven,
There's nothing surprising. The Hashtable is (well, let's assume so) in the RAM, and its searching algorithm is optimized for performance. The SQL Server keeps indexes on disk, so even if the algorithm is similar, loading the indexes from disk takes time (as well as transmitting the result set over the network or over a named pipe).
-- Sincerely, Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Steven Wolf" <ap****@gmx.net> wrote in message news:51**********************************@microsof t.com... Hi guys,
can a hashtable be faster than a sql server?? i made my own O/R mapping with an "entity cache" (caching all mapped objects). So, when i get some data from my sql server, i map that data to an entity-object and i leave a copy of it in the entity cache.
the entity cache is a simple hashtable, which stores as key: the ID of the entity ( the same id as the primary key of the sql-table ) and the entity type.. and as value: the object itself.
so, when i access the cache, i say: Contact contact = EntityCache.Get( 5109, typeof( Contact ) )
i just made some tests and i filled the cache with 1 mio. contacts. the result: searching the hashtable for one value, costs mostly ~0.000.007 sec! (nanoseconds).. thats amazing!! my sql server can never reach such values! my dev. machine is just an amd 2 ghz with 1 gb ram.
of course i can search in the cache only by id, but it is the same way as the sql server would search for an index, isn'it? i thought about, to setup an extra caching-server... just read a big sql-table and store everything in the entity-cache..(updating/inserting/deleting or searching by other values is another topic).
i cant believe it!
steven.
Steven Wolf wrote:
[...snip...] without taking care about the network-time, namepiping etc.,
ms-sql/indexes never get such results as the hashtable do.. i saw better results on PostgreSQL...
[...snip...] i am curious if sql server 2005 will conquer the speed as the hashtable
do...
[...snip...]
Don't expect any database to be even remotely as fast as a "simple" memory
access...
We are using Oracle 9 /10 as a database and even loading 1,000,000 rows of
data from file into memory and searching for a particular object (including
object creation) is faster than a simple query (first execution) against the
index of 1,000,000 rows in the database.
Steven Wolf wrote: can a hashtable be faster than a sql server??
Try thinking about "when X can X be faster than a SQL server?....", well
certainly if the SQL server uses one for it's implementation :)
Index'es in SQL are usually done as some kind of sorted tree's, which
are pretty fast for lookup. Hashtables (with proper hash-functions) are
*faster*.
The reason for choosing a sorted tree is that it has other nice
properties. Most importantly, it allows sorted traversal of the
elements, a thing which every "order by" and "join", pretty much depend on.
--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
It's possible that indexes reside in memory (provided they are small and
already loaded from DB), but even then, they are strored in the SQL server's
process space and searching an index from a client will be much slower than
searching a in process hashtable as it always involves a client/server
transition.
If however, you only consider SQL internal implementation of the index
tables and it's power compared to .NET's Hashtable lookup, I would expect
SQL to be on par.
Willy.
"Steven Wolf" <ap****@gmx.net> wrote in message
news:DF**********************************@microsof t.com... Hi Dmytro,
without taking care about the network-time, namepiping etc., ms-sql/indexes never get such results as the hashtable do.. i saw better results on PostgreSQL...
are you sure the indexes are stored on the harddisk? i thought they were in the RAM..
i am curious if sql server 2005 will conquer the speed as the hashtable do...
steven
"Dmytro Lapshyn [MVP]" wrote:
Hi Steven,
There's nothing surprising. The Hashtable is (well, let's assume so) in the RAM, and its searching algorithm is optimized for performance. The SQL Server keeps indexes on disk, so even if the algorithm is similar, loading the indexes from disk takes time (as well as transmitting the result set over the network or over a named pipe).
-- Sincerely, Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Steven Wolf" <ap****@gmx.net> wrote in message news:51**********************************@microsof t.com... > Hi guys, > > can a hashtable be faster than a sql server?? > i made my own O/R mapping with an "entity cache" (caching all mapped > objects). So, when i get some data from my sql server, i map that data > to > an > entity-object and i leave a copy of it in the entity cache. > > the entity cache is a simple hashtable, which stores as key: > the ID of the entity ( the same id as the primary key of the > sql-table ) > and > the entity type.. and as value: the object itself. > > so, when i access the cache, i say: Contact contact = EntityCache.Get( > 5109, > typeof( Contact ) ) > > i just made some tests and i filled the cache with 1 mio. contacts. > the result: searching the hashtable for one value, costs mostly > ~0.000.007 > sec! (nanoseconds).. thats amazing!! my sql server can never reach such > values! my dev. machine is just an amd 2 ghz with 1 gb ram. > > of course i can search in the cache only by id, but it is the same way > as > the sql server would search for an index, isn'it? i thought about, to > setup > an extra caching-server... just read a big sql-table and store > everything > in > the entity-cache..(updating/inserting/deleting or searching by other > values > is another topic). > > > i cant believe it! > > steven.
thank you all for the answers.
"Steven Wolf" wrote: Hi guys,
can a hashtable be faster than a sql server?? i made my own O/R mapping with an "entity cache" (caching all mapped objects). So, when i get some data from my sql server, i map that data to an entity-object and i leave a copy of it in the entity cache.
the entity cache is a simple hashtable, which stores as key: the ID of the entity ( the same id as the primary key of the sql-table ) and the entity type.. and as value: the object itself.
so, when i access the cache, i say: Contact contact = EntityCache.Get( 5109, typeof( Contact ) )
i just made some tests and i filled the cache with 1 mio. contacts. the result: searching the hashtable for one value, costs mostly ~0.000.007 sec! (nanoseconds).. thats amazing!! my sql server can never reach such values! my dev. machine is just an amd 2 ghz with 1 gb ram.
of course i can search in the cache only by id, but it is the same way as the sql server would search for an index, isn'it? i thought about, to setup an extra caching-server... just read a big sql-table and store everything in the entity-cache..(updating/inserting/deleting or searching by other values is another topic).
i cant believe it!
steven. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark |
last post by:
I'm using an enumerator to iterate through a HashTable that contains all
numeric keys. I'd like to iterarate through the HashTable based on the
ordered keys. Is there a quick way to do this?...
|
by: Vladimir C. |
last post by:
Hashtable map = new Hashtable();
map = 10;
map = 20;
foreach(DictionaryEntry e in map)
{
e.Value = 100;
Console.WriteLine("{0}: {1}", key, map);
}
|
by: davidw |
last post by:
I always use NameValueCollection. But I read an article says the only
differece between Hashtable and NameValueCollection is that
NameValueCollection could accept more than one value with same key?...
|
by: Matt C. |
last post by:
I bet I know the answer already.
I have a hashtable (hMaster) that holds several hashtables ("hTables") each
of which holds other hashtables ("hColumns"). Presently, I am getting at
the info I...
|
by: Sreekanth |
last post by:
Hello,
Is there any better collection than HashTable in terms of performance, when
the type of the key is integer?
Regards,
Sreekanth.
|
by: Dave |
last post by:
Hi all,
Is it possible to populate a listbox from a hashtable (complexbind) where
the ValueMember of the listbox maps to the "key" member of the hashtable AND
the DisplayMember of the listbox maps...
|
by: Vikas Kumar |
last post by:
Hashtable 7/7/2006 2:37 AM
I have this Hasttable windowList
Hashtable windowList = new Hashtable();
To this Hashtable I add a form with a string as key in the following manner.
The string is...
|
by: Martin Pöpping |
last post by:
Hello,
I´ve implemented a Hashtable with Int-Keys and Double Values.
Now I want to get the i-th Int-Key of my hashtable.
How do I do that?
I tried it like that:
ICollection intKeys =...
|
by: Macca |
last post by:
Hi,
My app needs to potentially store a large number of custom objects and be
able to iterate through them quickly. I was wondering which data structure
would be the most efficient to do this,a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |