title: APScheduler add lots of jobs concurrently (database Jobstore)
body: <p>How can I schedule lots of APScheduler jobs (4,000+) concurrently? (I must schedule all these after certain user events.) </p>
  
  <p>Iteratively calling <code>add_job</code> simply takes too long with many jobs. But when I try to use <code>AsyncIOScheduler</code> and the following async code, I don't get any added performance increase either.</p>
  
  <p><em>NOTE: my scheduler needs to connect to a SQL jobstore via SqlAlchemy</em></p>
  
  <pre><code>scheduler = AsyncIOScheduler(jobstores={"default": SQLAlchemyJobStore(url="a valid db connection str")})
  scheduler.start()
  
  def schedule_jobs_quickly():
      # init lots of (fake) jobs
      jobs = []
      for i in range(3000):
          jobs.append(i)
      send_time = datetime.datetime.now() + datetime.timedelta(days=2)
  
      # try to schedule jobs concurrently
      start_time = time.time()
      asyncio.get_event_loop().run_until_complete(schedule_all_jobs(jobs, send_time))
      duration = time.time() - start_time
      print(f"Created {len(jobs)} jobs in {duration} seconds")
  
  
  async def schedule_all_jobs(all_jobs, send_time):
      tasks = []
      for job in all_jobs:
          task = asyncio.ensure_future(schedule_job(job, send_time))
          tasks.append(task)
      await asyncio.gather(*tasks, return_exceptions=True)
  
  
  async def schedule_job(job, send_time):
      scheduler.add_job(send_email_if_needed, trigger=send_time)
  
  </code></pre>
  
  <p><strong>Result is very slow. How to speed this up?</strong></p>
  
  <pre><code>&gt;&gt;&gt; schedule_jobs_quickly()
  ...
  Created 3000 jobs in 401.9982771873474 seconds
  </code></pre>
  
  <p>For comparison, this is how long it took with a <code>BackgroundScheduler()</code> using the default memory jobstore:</p>
  
  <pre><code>Created 3000 jobs in 0.9155495166778564 seconds
  </code></pre>
  
  <p>So, it seems to be the database connections that are so expensive. Maybe there's a way to create multiple jobs using the same connection, instead of re-connecting for each <code>add_job</code>?</p>