What is the fastest way to send 100,000 HTTP requests in Python?

Twistedless solution: from urlparse import urlparse from threading import Thread import httplib, sys from Queue import Queue concurrent = 200 def doWork(): while True: url = q.get() status, url = getStatus(url) doSomethingWithResult(status, url) q.task_done() def getStatus(ourl): try: url = urlparse(ourl) conn = httplib.HTTPConnection(url.netloc) conn.request(“HEAD”, url.path) res = conn.getresponse() return res.status, ourl except: return “error”, ourl … Read more

SET NOCOUNT ON usage

Ok now I’ve done my research, here is the deal: In TDS protocol, SET NOCOUNT ON only saves 9-bytes per query while the text “SET NOCOUNT ON” itself is a whopping 14 bytes. I used to think that 123 row(s) affected was returned from server in plain text in a separate network packet but that’s … Read more

Is SELECT or INSERT in a function prone to race conditions?

It’s the recurring problem of SELECT or INSERT under possible concurrent write load, related to (but different from) UPSERT (which is INSERT or UPDATE). This PL/pgSQL function uses UPSERT (INSERT … ON CONFLICT .. DO UPDATE) to INSERT or SELECT a single row: CREATE OR REPLACE FUNCTION f_tag_id(_tag text, OUT _tag_id int) LANGUAGE plpgsql AS … Read more

Will two atomic writes to different locations in different threads always be seen in the same order by other threads?

This kind of reordering test is called IRIW (Independent Readers, Independent Writers), where we’re checking if two readers can see the same pair of stores appear in different orders. Related, maybe a duplicate: Acquire/release semantics with 4 threads The very weak C++11 memory model does not require that all threads agree on a global order … Read more

Is there an advantage to use a Synchronized Method instead of a Synchronized Block?

Can anyone tell me the advantage of the synchronized method over the synchronized block with an example? Thanks. There is not a clear advantage of using synchronized method over the block. Perhaps the only one ( but I wouldn’t call it an advantage ) is you don’t need to include the object reference this. Method: … Read more

How to wait for all threads to finish, using ExecutorService?

Basically on an ExecutorService you call shutdown() and then awaitTermination(): ExecutorService taskExecutor = Executors.newFixedThreadPool(4); while(…) { taskExecutor.execute(new MyTask()); } taskExecutor.shutdown(); try { taskExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { … }

Random errors when changing series using JFreeChart

Your snippet is incorrectly synchronized; you should update your dataset from the process() method of a SwingWorker, as shown here. Because your domain is “the number of my inner iterations”, don’t use a DateAxis; instead, use a NumberAxis, as shown in ChartFactory.createXYLineChart(). Addendum: This variation on the example plots the worker’s progress on a line … Read more