473,402 Members | 2,050 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,402 software developers and data experts.

cost of creating threads


hi!

i have an application that runs on a pocket pc. the application has a
server which responds to UDP requests. each request contains the address
of another server (say, server_b). the pocket pc server recieves these UDP
requests and creates an SSL client connection to sercer_b

my current setup is iterative and i am thinking of making it into a
threaded application.since i have a gui, the pocket pc server already runs
in a separate thread. my question is, in terms of memory and processing
power, how much overhead will creating threads cost. My sessions are quite
short lived. if this was a pc application, i'd go ahead with a threads. But
since this is a pocket pc (the processor is a XScale 400 MHz but really all
said and done we only ever have around 200 MHz or so - memory available
would be optimistically speaking, around 12 MB)

any thoughts on what threads would cost me?

thanks

cheers


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
4 3125
hi,

In the documentation is a short comprehensive list of what server
options for handling connections are usefull in what situations. .
See chapter 15.1.2 on http://www.cherrypy.org/static/html/tut/node17.html .
While you have a tiny server, i would recommend a thread-pool of about 2
to 3 threads. This at least cuts down the time needed for thread creation.

Cheers!
Remco

Ajay wrote:
hi!

i have an application that runs on a pocket pc. the application has a
server which responds to UDP requests. each request contains the address
of another server (say, server_b). the pocket pc server recieves these UDP
requests and creates an SSL client connection to sercer_b

[snip]
Jul 18 '05 #2
Ajay wrote:
i have an application that runs on a pocket pc. [...] my question is, in terms of memory and processing
power, how much overhead will creating threads cost.


I've never worked with Pocket-PC, but the answer is almost
certainly "not much". You can get reasonable bounds with simple
test programs. I'll include a Python thread creation timer
below.

Threading has improved vastly in recent years, and the current
versions of the popular operating systems now have excellent
thread support. As one might expect, out-dated ideas about
the cost of threads are still widespread.
--Bryan

import thread
import time

lock = thread.allocate_lock()
lst = [0]

def increment():
lock.acquire()
lst[0] += 1
lock.release()

def mass_thread(nthreads):
print "Running %d threads..." % nthreads
i = 0
benchmark = time.clock()
while i < nthreads:
try:
thread.start_new_thread(increment, ())
i += 1
except:
# thread.error is undocumented, so catch all
time.sleep(0.05)
go = 1
while go:
time.sleep(0.1)
lock.acquire()
if lst[0] == nthreads:
go = 0
lock.release()
benchmark = time.clock() - benchmark
print "All %s threads have run." % lst[0]
print "That took %f seconds." % benchmark

if __name__ == '__main__':
mass_thread(10000)
Jul 18 '05 #3
Remco Boerma wrote:
In the documentation is a short comprehensive list of what server
options for handling connections are usefull in what situations. .
See chapter 15.1.2 on http://www.cherrypy.org/static/html/tut/node17.html . While you have a tiny server, i would recommend a thread-pool of about 2
to 3 threads. This at least cuts down the time needed for thread

creation.

What happens if all three threads are blocked, perhaps waiting
for server_b, when a new request comes in?
--
--Bryan
Jul 18 '05 #4
Hi,

Bryan Olson wrote:
Remco Boerma wrote:
> In the documentation is a short comprehensive list of what server
> options for handling connections are usefull in what situations. .
> See chapter 15.1.2 on

http://www.cherrypy.org/static/html/tut/node17.html .
> While you have a tiny server, i would recommend a thread-pool of about 2
> to 3 threads. This at least cuts down the time needed for thread

creation.

What happens if all three threads are blocked, perhaps waiting
for server_b, when a new request comes in?


I guess it would indeed wait until one of the first 3 threads has closed
it's connection, or a timeout occurs. But you ought to test it, just to
make sure. . With a little statistics usage, you would be able to create
new threads on the fly if many connections are established in a short
time, releasing the threads when idle for x seconds. . This would allow
you to use more resources when needed, and releasing them when done.

I don't have any knowledge of pocket pc's, but is there any way you can
use twisted? I've read/heared it's master using only a single thread. .

Cheers!
Jul 18 '05 #5

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

Similar topics

11
by: Przemysław Różycki | last post by:
Hello, I have written some code, which creates many threads for each connection ('main connection'). The purpose of this code is to balance the load between several connections ('pipes'). The...
6
by: Christian Buckl | last post by:
Hi, I try to implement my own thread class based on POSIX threads. I want my class to manage everything (creation of threads, exception handling...). This includes also some functions that need to...
5
by: Adam Clauss | last post by:
I am creating a plugin for MS Outlook. Upon clicking a toolbar button, I create series of threads (variable number each time). Within each thread, I start a form using Application.Run(...). This...
5
by: Bob Bins | last post by:
Is there a way to create a shared lock using the Monitor class or any other synchronization class in .NET? So I have one resource that may have multiple threads using it at once but a second...
12
by: David Beoulve | last post by:
In my windows C# app, I create a thread to separate the main code block from the GUI, which recursively sorts through all the directories starting from a given point, and every time it finds a...
7
by: John A Grandy | last post by:
I'm trying to get a decent idea of the relative performance of three types of implementations of data-access classes in ASP.NET 2.0. I believe this boils down to a more basic question regarding...
5
by: dk60 | last post by:
Here is a problem I encountered concerning threads: Here is the code in Form1 button click handler: AddForm addForm = new AddForm(booksDataSet.Titles); Thread addTitleThread=new Thread(new...
9
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
2
by: raisq1 | last post by:
I have two tables: Expense Table: ( Contains miscellaneous expenses incurred while the goods are transported ) Expense_Type ContainerID Expense_Dollar Labour 20301 5000.00 ...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.