473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Hashtable faster than SQL ?!!

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.
Nov 17 '05 #1
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.


Nov 17 '05 #2
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.


Nov 17 '05 #3
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.
Nov 17 '05 #4


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 <=-
Nov 17 '05 #5
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.


Nov 17 '05 #6
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.

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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?...
4
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); }
7
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?...
4
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...
16
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.
5
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...
5
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...
8
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 =...
15
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.