diff --git a/common/gearman.go b/common/gearman.go index 3e7a72b..969c457 100644 --- a/common/gearman.go +++ b/common/gearman.go @@ -15,7 +15,7 @@ const ( // queue size QUEUE_SIZE = 8 // read buffer size - BUFFER_SIZE = 2048 + BUFFER_SIZE = 1024 // \x00REQ REQ = 5391697 diff --git a/example/py/foobar.py b/example/py/foobar.py new file mode 100755 index 0000000..ac544f7 --- /dev/null +++ b/example/py/foobar.py @@ -0,0 +1,36 @@ +#!/usr/bin/python + +import gearman + +def check_request_status(job_request): + if job_request.complete: + print "Job %s finished! Result: %s - %s" % (job_request.job.unique, job_request.state, job_request.result) + elif job_request.timed_out: + print "Job %s timed out!" % job_request.unique + elif job_request.state == JOB_UNKNOWN: + print "Job %s connection failed!" % job_request.unique + +def main(): + client = gearman.GearmanClient(['localhost:4730', 'otherhost:4730']) + for i in range(100000000): + try: + completed_job_request = client.submit_job("ToUpper", "arbitrary binary data") + check_request_status(completed_job_request) + except Exception as e: + print type(e) + + try: + completed_job_request = client.submit_job("SysInfo", "") + check_request_status(completed_job_request) + except Exception as e: + print type(e) + + try: + completed_job_request = client.submit_job("MemInfo", "") + check_request_status(completed_job_request) + except Exception as e: + print type(e) + +if __name__ == '__main__': + main() + diff --git a/example/worker b/example/worker new file mode 100755 index 0000000..0558732 Binary files /dev/null and b/example/worker differ diff --git a/worker/agent.go b/worker/agent.go index 0ede427..708cf50 100644 --- a/worker/agent.go +++ b/worker/agent.go @@ -116,7 +116,7 @@ BEGIN: data = append(data, <-a.in...) } } else { - for { + for i := 0; i < 10; i ++ { buf := make([]byte, common.BUFFER_SIZE) var n int if n, err = a.conn.Read(buf); err != nil {